AngularJS / Jade错误:参数'MyController'不是一个函数,没有定义(MEAN)

我知道这个问题的变化已经被问了好几次了,但是我已经尝试了其他OP的几个build议的解决scheme,还没有能够解决这个问题,并且希望得到一些解释。

我正在使用基本的意思todo列表应用程序( http://www.mean.io/ )。 在执行一个简单的控制器后,我遇到了“Error:Argument'nameOfMyController'不是一个函数,得到了未定义。

这是我在哪里:

app.js(样板)

window.app = angular.module('mean', ['ngCookies', 'ngResource', 'ui.bootstrap', 'ui.route', 'mean.system', 'mean.articles' ]); angular.module('mean.system', []); angular.module('mean.articles', []); 

我试着修改这里引用的内容,例如,向数组中添加mean.controller,但显然不是正确的方法,因为它告诉我模块不存在。

这里是我的taskController.js(我遵循的一个平均教程使taskController一个独立的function,但我声称它作为一个构造函数的angular度的文档说的方式)

 var mean = angular.module('mean',[]); mean.controller('taskController', function taskController($scope){ $scope.todos = []; $scope.doneFilter = { done : true }; $scope.notDoneFilter = { done : false }; $scope.setTodos = function(todos){ $scope.todos = todos; }; }); 

我也尝试了angular.module('mean.system').controller('taskController',function taskController($ scope){…},结果相同。

好吧,现在的意见:包括ng-app在default.jade

 !!! 5 html(ng-app='mean', lang='en', xmlns='http://www.w3.org/1999/xhtml', xmlns:fb='https://www.facebook.com/2008/fbml', itemscope='itemscope', itemtype='http://schema.org/Product') include ../includes/head body ... include ../includes/foot 

那么在index.jade中我有:

 extends layouts/default block head script(type='text/javascript', src='/js/controllers/taskController.js') block content section(data-ng-view) div.container(ng-controller="taskController", ng-init="setTodos( #{JSON.stringify(todos)} )") ... div.row(ng-repeat="todo in todos | filter:notDoneFilter") label.checkbox input(type="checkbox", ng-model="todo.done") | {{ todo.description }} span.datestring i {{ todo.due | date: 'MMM d, yyyy' }} ... div.row(ng-repeat="todo in todos | filter:doneFilter") label.checkbox input(type="checkbox", checked="true") del {{ todo.description }} span.datestring i {{ todo.due | date: 'MMM d, yyyy' }} 

foot.jade插入:

 //AngularJS script(type='text/javascript', src='/lib/angular/angular.js') script(type='text/javascript', src='/lib/angular-cookies/angular-cookies.js') script(type='text/javascript', src='/lib/angular-resource/angular-resource.js') 

我不认为我错过了任何angular度指令和控制器本身应该工作,所以我假设这是一个基本的应用程序体系结构问题,我不明白事情如何融合在一起。 任何帮助,将不胜感激。

这个错误大多出现在angularjs无法在任何模块中定位控制器的时候。 当您不小心重新定义模块时会发生这种情况。 在你的情况下,我看到了

window.app = angular.module('mean', ['ngCookies', 'ngResource', 'ui.bootstrap', 'ui.route', 'mean.system', 'mean.articles' ]);

接着

var mean = angular.module('mean',[]);

这个语法重新定义了模块。

使用angular.module('mean')获取现有模块而不使用第二个参数。

我刚才有这个问题。 我尝试了上面所有的build议,没有任何工作。 然后,我将AngularJS从版本1.3.9-build.3746降级到版本1.2.8。 这就是我使用testing版本所得到的结果。