注意是angular1.5.x, 不是2
我在根模块(App)中依赖了ngResource模块和一个自定义的foo模块. 我的这个foo模块要使用ngResource模块的服务, 就不需要再次引入啦. angular是在什么时候把ngResource模块引入到foo模块的?
虽然我们都知道这个app模块是跟模块, 可是我并没有在任何地方告诉angular, 这个app就是我的根模块呀?
app.js
angular.module('app', ['foo','ngResource']);
foo.js
var phone = angular.module('foo', []);
phone.factory('Foo', ['$resource'], function($resource) {
// 使用$resource
})
这样的代码, Foo这个模块是如何能自动注入$resource的?
phpcn_u15822017-05-15 17:15:45
Regarding dependency injection, it is maintained by Angular. Naturally, everything that has been injected will not be loaded repeatedly.
And app is the root module, it depends on how you enable your Angular, such as:
ng-app="app"
or
angular.bootstrap(document, ['app']);
are all explicitly stated app
as the start of enabling the module.