Tus*_*har -7 dependency-injection angularjs
为什么AngularJS []在定义没有依赖关系的模块时需要空数组.Angular DevTeam可以检查第二个参数,如果undefined没有依赖关系.
angular.module("app", [])
Run Code Online (Sandbox Code Playgroud)
[]没有通过时会出现奇怪的错误.
我的问题是为什么他们需要空阵列?
因为angular.module('app')1参数具有不同的功能 - 获取已存在的模块而没有对其的代码引用.
原因如下:
angular.module('app', []); // Define the module.
angular.module('app'); // Get the module.
Run Code Online (Sandbox Code Playgroud)
和以下一样有效:
var app = angular.module('app', []); // Define the module and assign to variable.
Run Code Online (Sandbox Code Playgroud)