Angularjs 出于DI目的,将模块插入其他模块的条件是什么?
我有一个有角度的应用程序,在其中我可以在app.coffee文件中看到这个咖啡Angularjs 出于DI目的,将模块插入其他模块的条件是什么?,angularjs,Angularjs,我有一个有角度的应用程序,在其中我可以在app.coffee文件中看到这个咖啡 app = angular.module 'app', [ 'ngRoute', 'ngResource', 'ui.router', 'app.filters', 'app.services', 'app.directives', 'app.controllers', 'app.templates', ] angular.module('app.services', ['ngRes
app = angular.module 'app', [
'ngRoute',
'ngResource',
'ui.router',
'app.filters',
'app.services',
'app.directives',
'app.controllers',
'app.templates',
]
angular.module('app.services', ['ngResource'])
angular.module('app.controllers',[])
angular.module('app.directives', [])
angular.module('app.filters', [])
angular.module('app.templates', [])
angular.module('app.models', [])
我真的不明白为什么我必须直接将ngResource注入app.services模块和app模块。当然,我可以将所有依赖项连接到应用程序模块中,然后它将允许全局访问其余模块?当您编写
app=angular.module'app'[
"ngRoute",,
“ngResource”,
“ui.router”,
'应用程序过滤器',
“应用程序服务”,
“应用程序指令”,
'应用程序控制器',
'应用程序模板',
]
这意味着这些是您的应用程序的依赖项
当你写作时
angular.module('app.services',['ngResource'])
这意味着app.services
具有依赖性ngResource
。关于你为什么需要再写一次的问题。这相当简单,app.services
使用ngResource
。如果您不希望整个应用程序具有ngresource
依赖关系,您可以在第一行忽略它,但它必须存在于app.services
您可以阅读更多关于它的内容因此我可以将其从angular.module('app.services',['ngResource'])中删除吗行并仍然可以在我的app.services模块中访问它?仅当另一个模块没有此依赖项时。抱歉确认:如果我希望应用程序可以访问整个应用程序,那么它将进入“app”,因此我永远不需要将其放在app.services中,但如果我只想将其放在app.services中,那么我将其放在那里。如果是这样的话,那么在这两个地方都有它是没有用的。我也可以把它放在“应用程序”中,因为我的整个应用程序都需要它。是吗?更正:从您的第一条评论:是的,如果您已经在app
中注入了依赖项,那么在声明app.services
模块时无需再次包含它。你的第二个评论:是的。