angularjs defining services for the same module in different files

后端 未结 2 1258

I have two files in which I define services in my angular app, but when I try to use them both in my directive, I get an error saying the service provider is not found for w

相关标签:
2条回答
  • 2020-12-29 08:37

    This is from the docs:

    Beware that using angular.module('myModule', []) will create the module myModule and overwrite any existing module named myModule. Use angular.module('myModule') to retrieve an existing module.

    Found here: https://docs.angularjs.org/guide/module

    0 讨论(0)
  • 2020-12-29 08:53

    This is possible, however will be error prone, hence not recommended

    Make small modification to what you are already doing

    Just do not re-declare the module variable in other files other than service1.js or put the module definition to a file of its own and include these JS file in the order of Module.js, services.js, directive.js then it will work

    0 讨论(0)
提交回复
热议问题