AngularJS /玉错误:参数'myController的“不是一个函数,得到了未定义(MEAN) [英] AngularJS/Jade Error: Argument 'MyController' is not a function, got undefined (MEAN)

查看:266
本文介绍了AngularJS /玉错误:参数'myController的“不是一个函数,得到了未定义(MEAN)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题的变化已经被问了好几次,但我试了几个建议的解决方案为其他有机磷农药,一直没能解决这个问题,并且将AP preciate一些澄清。

I know variations of this question have already been asked several times, but I've tried several suggested solutions for other OPs, haven't been able to resolve this, and would appreciate some clarification.

我的基本平均待办事项列表应用工作( http://www.mean.io/ )。实现一个简单的控制器我运行到之后的错误:参数'nameOfMyController不是一个函数,得到了不确定的。

I'm working with the basic mean todo list app (http://www.mean.io/). After implementing a simple controller I'm running into the "Error: Argument 'nameOfMyController' is not a function, got undefined."

下面是我在哪里:

app.js(样板)

app.js (boilerplate)

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到阵列但这显然不是,因为它告诉我的模块不存在这样做的正确方法。

I've tried modifying what's referenced here, like, for example, adding mean.controller to the array but that clearly isn't the right way to do it because it tells me the module doesn't exist.

这里是我的taskController.js(平均教程我也跟着做taskController一个独立的功能,但我宣布它为构造角的文档说的方式)

here's my taskController.js (a mean tutorial I followed made taskController a standalone function but I'm declaring it as a constructor the way angular's docs say to)

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')。控制器('taskController',功能taskController($范围){...},同样的结果。

I also tried angular.module('mean.system').controller('taskController', function taskController($scope){ ... }, same result.

确定现在的观点:在default.jade包括NG-应用

ok now for the views: included ng-app in 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我有:

then in index.jade I have:

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插入:

foot.jade inserts:

//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')

我不知道的认为的我错过任何角度指令和本身应该工作的控制器,所以我假定这是一个基本的应用程序架构的问题,我不明白的事情如何适应一起。任何帮助将是AP preciated。

I don't think I'm missing any angular directives and the controller itself should work, so I'm assuming this is a basic app architecture problem where I don't understand how things fit together. Any help would be appreciated.

推荐答案

此错误大多是来当angularjs不能任何模块中找到控制器。发生这种情况时,你不小心重新定义模块。
你的情况我看到

This error mostly comes when angularjs is not able to locate the controller in any module. This can happen when you accidentally redefine the module. In your case i see that

window.app = angular.module('平均',['ngCookies','ngResource','ui.bootstrap','ui.route','mean.system','是什么意思.articles']);

然后

VAR平均= angular.module('平均',[]);

本语法重新定义模块。

This syntax redefine the module.

要使用获得现有的模块 angular.module('平均')没有第二个参数。

To get the existing module using angular.module('mean') without the second parameter.

这篇关于AngularJS /玉错误:参数'myController的“不是一个函数,得到了未定义(MEAN)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆