1

我想将我的子模块注入主应用程序,但我有注入错误

(错误:[ng:areq] http://errors.angularjs.org/1.3.5/ng/areq?p0=SelectionCtrl&p1=not%20aNaNunction%2C%20got%20undefined

这是我的主要应用

在此处输入图像描述

这是我的子模块 在此处输入图像描述

我该如何解决?谢谢!

4

1 回答 1

2

你搞砸了模块声明。你宣布angular.module('app.newProject')了​​两次。

在您第一次注册时创建它SelectionCtrl。之后,您创建了另一个具有相同名称angular.module('app.newProject,[]')的具有依赖关系和注册 TabController1控制器的模块。当您创建第二个模块时,它会覆盖第一个模块,现在它只有TabController1这就是为什么SelectionCtrl需要 angular 抛出错误。

有几种方法可以解决这种方法。

方法一

创建一个模块并将其存储在某个变量中,并随时使用它。

var controllerApp = angular.module('app.newProject', [])
.controller('SelectionCtrl',function(){ 
    //code here
});

controllerApp.controller('TabController1',function(){
 //your code here
});

方法二

创建一个模块,无论何时要使用它,都可以无依赖地使用它。

angular.module('app.newProject', [])
.controller('SelectionCtrl',function(){ 
    //code here
});

angular.module('app.newProject').controller('TabController1',function(){
 //your code here
});

方法3(我不喜欢这种方法)

创建一个模块并以线性方式附加组件。

angular.module('app.newProject', [])
.controller('SelectionCtrl',function(){ 
    //code here
})
.controller('TabController1',function(){
 //your code here
});

我希望您选择方法 2,它可以通过引用模块来为您提供任何绑定组件。

于 2015-01-23T20:25:52.753 回答