angular.module:第二个参数是做什么的?
angular.module: what does the second argument do?
要引用 Angular 1.4 中的现有模块,我这样做:
angular.module('hotdog')
我可以像这样向模块添加内容:
angular.module('hotdog').factory(...).component(...)
首先要创建模块,模块函数需要依赖模块的第二个参数。
angular.module('hotdog', ['sausage', 'bun'])
我的问题是,如果有的话,依赖项列表实际上做了什么?我可以去掉依赖项,它 似乎 不会破坏任何东西,即使我在 'hotdog' 模块中引用属于 'sausage' 的服务,并且'bun'.
angular.module('hotdog', [])
documentation 不是很有帮助。
"If specified then new module is being created. If unspecified then the module is being retrieved for further configuration."
我找到了 similar question 但我对答案不满意。
第二个参数用于依赖注入。您可能会发现 this 文档更有帮助。
Modules can list other modules as their dependencies. Depending on a module implies that the required module needs to be loaded before the requiring module is loaded. In other words the configuration blocks of the required modules execute before the configuration blocks of the requiring module. The same is true for the run blocks. Each module can only be loaded once, even if multiple other modules require it.
如果您声明依赖项或将第二个参数保留为空块[],则意味着您正在声明模块的新实例。如果你完全离开它,你正在引用一个现有的模块。
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.
要引用 Angular 1.4 中的现有模块,我这样做:
angular.module('hotdog')
我可以像这样向模块添加内容:
angular.module('hotdog').factory(...).component(...)
首先要创建模块,模块函数需要依赖模块的第二个参数。
angular.module('hotdog', ['sausage', 'bun'])
我的问题是,如果有的话,依赖项列表实际上做了什么?我可以去掉依赖项,它 似乎 不会破坏任何东西,即使我在 'hotdog' 模块中引用属于 'sausage' 的服务,并且'bun'.
angular.module('hotdog', [])
documentation 不是很有帮助。
"If specified then new module is being created. If unspecified then the module is being retrieved for further configuration."
我找到了 similar question 但我对答案不满意。
第二个参数用于依赖注入。您可能会发现 this 文档更有帮助。
Modules can list other modules as their dependencies. Depending on a module implies that the required module needs to be loaded before the requiring module is loaded. In other words the configuration blocks of the required modules execute before the configuration blocks of the requiring module. The same is true for the run blocks. Each module can only be loaded once, even if multiple other modules require it.
如果您声明依赖项或将第二个参数保留为空块[],则意味着您正在声明模块的新实例。如果你完全离开它,你正在引用一个现有的模块。
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.