Angularjs: Error: [ng:areq] Argument 'HomeController' is not a function, got undefined

前端 未结 24 1548
抹茶落季
抹茶落季 2020-11-27 12:22

This is my demo using angularjs, for creating a service file, and adding service to a controller.

I have two problems with my demo:

  • One is when I put <
相关标签:
24条回答
  • 2020-11-27 12:55

    Also ensure that your controllers are defined within script tags toward the bottom of your index.html just before the closing tag for body.

     <!-- build:js({.tmp,app}) scripts/scripts.js -->
        <script src="scripts/app.js"></script>
        <script src="scripts/controllers/main.js"></script>
        <script src="scripts/controllers/Administration.js"></script>
        <script src="scripts/controllers/Leaderboard.js"></script>
        <script src="scripts/controllers/Login.js"></script>
        <script src="scripts/controllers/registration.js"></script>
    

    provided everything is spelled "correctly" (the same) on your specific.html, specific.js and app.js pages this should resolve your issue.

    0 讨论(0)
  • 2020-11-27 12:56

    I got the same error. I defined java script like this

    <script src="controllers/home.js" />
    

    then I changed to the this

    <script src="controllers/home.js"></script>
    

    After this my problem is solved.

    0 讨论(0)
  • 2020-11-27 12:57

    I also got this error.

    I had to add my new controller to routing information. \src\js\app.js

    angular.module('Lillan', [
      'ngRoute',
      'mobile-angular-ui',
      'Lillan.controllers.Main'
    ])
    

    I added my controller to make it look like

    angular.module('Lillan', [
      'ngRoute',
      'mobile-angular-ui',
      'Lillan.controllers.Main',
      'Lillan.controllers.Growth'
    ])
    

    Cheers!

    0 讨论(0)
  • 2020-11-27 12:59

    I had the same problem, but I forgot to include the file into grunt/gulp minimization process.

    grunt.initConfig({
      uglify: {
        my_target: {
          files: {
            'dest/output.min.js': ['src/input1.js', 'src/missing_controller.js']
          }
        }
      }
    });
    

    Hope that helps.

    0 讨论(0)
  • 2020-11-27 13:01

    I experienced this error once. My problem was that I wasn't adding the FILE_NAME_WHERE_IS_MY_FUNCTION.js

    so my file.html never found where my function was

    Once I add the "file.js" I resolved the problem

    <html ng-app='myApp'>
        <body ng-controller='TextController'>
        ....
        ....
        ....
        <script src="../file.js"></script>
        </body>
    </html>
    
    0 讨论(0)
  • 2020-11-27 13:03

    In my situation this error appeared when I didn't declare function within an array argument.

    The one with error:

    taskAppControllers.controller('MainMenuCtrl', []);
    

    The fixed one:

    taskAppControllers.controller('MainMenuCtrl', [function(){
    
    }]);
    
    0 讨论(0)
提交回复
热议问题