如何修复 angular.module 不使用依赖模块?
How to fix an angular.module not working with dependent modules?
我很清楚 angular.module 的工作原理,但不知为何我对此一头雾水。
在我的代码中有以下内容
var app = angular.module("myApp", [])
app.controller("MainCtrl", ...)
但我的代码仅在没有依赖模块数组时才有效,如下所示:
var app = angular.module("myApp");
app.controller("MainCtrl",...)
我一点也不知道是什么导致了这个问题,因为我一直明白需要空数组。
I've always understood the need for the empty array
仅在创建模块时才需要作为第二个参数的数组。所以
angular.module("myApp", [])
您创建了新模块。还有
angular.module("myApp")
您检索了之前创建的已经存在的模块。
my code only works when there is no array for dependent modules
表示您已经创建了模块myApp
。在这种情况下,您不必再次重新创建它,因为它会清除所有以前注册的控制器等。
我很清楚 angular.module 的工作原理,但不知为何我对此一头雾水。
在我的代码中有以下内容
var app = angular.module("myApp", [])
app.controller("MainCtrl", ...)
但我的代码仅在没有依赖模块数组时才有效,如下所示:
var app = angular.module("myApp");
app.controller("MainCtrl",...)
我一点也不知道是什么导致了这个问题,因为我一直明白需要空数组。
I've always understood the need for the empty array
仅在创建模块时才需要作为第二个参数的数组。所以
angular.module("myApp", [])
您创建了新模块。还有
angular.module("myApp")
您检索了之前创建的已经存在的模块。
my code only works when there is no array for dependent modules
表示您已经创建了模块myApp
。在这种情况下,您不必再次重新创建它,因为它会清除所有以前注册的控制器等。