【问题标题】:what is this angular error?这个角度误差是什么?
【发布时间】:2014-07-19 08:14:08
【问题描述】:

刚刚做了一个简单的控制器,注入了一些东西。

var SimpleProductListController = BaseController.extend({

    _notifications:null,
    _productsModel:null,

    init:function($scope,ProductsModel,$route){
    },    
    defineListeners:function(){
        this._super();            
    },
    destroy:function(){

    }
})
/...

SimpleProductListController.$inject = ['$scope','ProductsModel','$route'];

控制台错误指向这一点: http://errors.angularjs.org/1.2.16/ng/areq?p0=SimpleProductListController&p1=not%20aNaNunction%2C%20got%20undefined

Argument 'SimpleProductListController' is not aNaNunction, got undefined

我应该如何调试呢?我得到了batarang,但它在这里什么也没做。

【问题讨论】:

  • 什么是BaseController?这段代码看起来很 ember-y,而不是 angular-y。
  • github.com/trochette/Angular-Design-Patterns-Best-Practices 相比提升了不少,但你如何调试 Angular?所有的错误都是没有意义的
  • Angular 实际上通常很容易调试。像这样的错误通常与喷油器有关。所以 - 有一些依赖项需要您的 SimpleProductListController 并且您的应用程序在任何地方都找不到它。也许你在双重声明你的模块?例如:var app = angular.module('myModule',[]); /*then somewhere else*/ var app = angular.module('myModule',[/*this second [] parameter will bulldoze/undefine your first module*/]);

标签: javascript angularjs arguments


【解决方案1】:

基本上,Angular 是在说 SimpleProductListController 是未定义的。

当我收到该错误时,这是​​因为我创建了一个控制器并尝试将其注入我的应用程序,但我没有通过将脚本标记添加到我的 index.html 文件来加载定义该控制器的文件。

【讨论】:

  • 就是这样,但多么可怕的错误消息。它在语法上不正确,更不用说可读或可辨别了。 Argument 'SimpleProductListController' is not aNaNunction, got undefined 这是一个 ngBonics
  • 这是一个可怕的错误描述。但 2 小时后,我发现我在控制器名称中打错了字。 FML。
猜你喜欢
  • 1970-01-01
  • 2021-11-17
  • 1970-01-01
  • 2014-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多