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

前端 未结 24 1577
抹茶落季
抹茶落季 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:40

    This creates a new module/app:

    var myApp = angular.module('myApp',[]);
    

    While this accesses an already created module (notice the omission of the second argument):

    var myApp = angular.module('myApp');
    

    Since you use the first approach on both scripts you are basically overriding the module you previously created.

    On the second script being loaded, use var myApp = angular.module('myApp');.

提交回复
热议问题