错误:[NG:AREQ]从角控制器 [英] Error: [ng:areq] from angular controller
问题描述
这是一个长镜头,但有没有人见过这个错误?我想加上'转运'使用前preSS,角和MongoDB。每当我访问由转运控制器统治的页面我得到这个错误:
错误:[NG:AREQ] http://errors.angularjs.org/1.2.12/ng/areq?p0=TransportersController&p1=not%20aNaNunction%2C%20got%20undefined
在错误(原生)
在http://本地主机:3000 / lib目录/角/ angular.min.js:6:450
在TB(HTTP://本地主机:3000 / lib目录/角/ angular.min.js:18:360)
在帕(HTTP://本地主机:3000 / lib目录/角/ angular.min.js:18:447)
在http://本地主机:3000 / lib目录/角/ angular.min.js:62:17
在http://本地主机:3000 / lib目录/角/ angular.min.js:49:43
在Q(HTTP://本地主机:3000 / lib目录/角/ angular.min.js:7:386)
在H(HTTP://本地主机:3000 / lib目录/角/ angular.min.js:48:406)
在f(HTTP://本地主机:3000 / lib目录/角/ angular.min.js:42:399)
在http://本地主机:3000 / lib目录/角/ angular.min.js:42:67
该转运控制器看起来是这样的:
使用严格的;angular.module('mean.transporters')。控制器('TransportersController',['$范围,$ routeParams','$的位置,环球,转运,函数($范围,$ routeParams,$位置,全球,运输){
$ scope.global =全局; $ scope.create =功能(){
VAR转运=新的转运({
名称:this.name,
natl_id:this.natl_id,
电话:this.phone
});
转运。$保存(功能(响应){
$ location.path('运输/+ response._id);
}); this.title ='';
this.content ='';
}; $ scope.remove =功能(转运){
如果(转运){
。转运$删除(); 对于(VAR我在$ scope.transporters){
如果($ scope.transporters [I] ===转运){
$ scope.transporters.splice(I,1);
}
}
}
其他{
。$ scope.transporter $删除();
$ location.path('转运');
}
}; $ scope.update =功能(){
VAR转运= $ scope.transporter;
如果(!transporter.updated){
transporter.updated = [];
}
transporter.updated.push(新的Date()的getTime()); 转运。$更新(函数(){
$ location.path('运输/+ transporter._id);
});
}; $ scope.find =功能(){
Transporters.query(功能(运输){
$ scope.transporters =转运;
});
}; $ scope.findOne =功能(){
Transporters.get({
transporterId:$ routeParams.transporterId
},功能(转运){
$ scope.transporter =转运;
});
};
}]);
在我的意见我所说的列表,并创建方法。它们所产生的上述错误
我得到这个从 NG角文档:AREQ 虽然还是想不通这是怎么回事
AngularJS常常断言,某些值将是present和truthy
使用一个辅助函数。如果断言失败,这个错误被抛出。
要解决这个问题,确保断言预期值
定义和truthy。
块引用>下面是调用视图控制器
公共/视图/运输/ list.html
:<节数据-NG-控制器=TransportersController数据-NG-的init =找到()>
< UL类=无样式的运输>
<李数据-NG-重复=转运运输>
<跨度> {{transporter.created |日期:'中'}}< / SPAN> /
&所述; H2>&下;一个数据纳克-HREF =#!/转运/ {{transporter._id}}> {{transporter.name}}&下; / A>&下; / H2>
< DIV> {{transporter.natl_id}}< / DIV>
< DIV> {{transporter.phone}}< / DIV>
< /李>
< / UL>
< H1数据-NG-隐藏=转运|| transporters.length!>暂时还没有转运。 < BR>你为什么不< A HREF =!/#/运输/创建>创建一个< / A>< / H1>
< /节>转运服务code:
angular.module('transporterService',[])
.factory('转运',['$ HTTP',函数($ HTTP){
//返回所有对象的承诺
返回{
得到:函数(){
返回$ http.get('/ API /运输');
},
创建:功能(transporterData){
返回$ http.post('/ API /运输',transporterData);
},
删除:函数(ID){
返回$ http.delete('/ API /运输/'+ id)的;
}
};
}]);
解决方案我经历过这种错误一次。问题是我在两个地方使用不同的参数已经定义angular.module()。
例如:
VAR的MyApp = angular.module('MyApp的',[]);
在其他地方,
VAR MyApp2 = angular.module('MyApp的',['ngAnimate']);
This is a long shot, but has anyone seen this error before? I am trying to add 'Transporters' using express, angular and mongoDB. I get this error whenever I access a page ruled by the transporters controller:
Error: [ng:areq] http://errors.angularjs.org/1.2.12/ng/areq?p0=TransportersController&p1=not%20aNaNunction%2C%20got%20undefined at Error (native) at http://localhost:3000/lib/angular/angular.min.js:6:450 at tb (http://localhost:3000/lib/angular/angular.min.js:18:360) at Pa (http://localhost:3000/lib/angular/angular.min.js:18:447) at http://localhost:3000/lib/angular/angular.min.js:62:17 at http://localhost:3000/lib/angular/angular.min.js:49:43 at q (http://localhost:3000/lib/angular/angular.min.js:7:386) at H (http://localhost:3000/lib/angular/angular.min.js:48:406) at f (http://localhost:3000/lib/angular/angular.min.js:42:399) at http://localhost:3000/lib/angular/angular.min.js:42:67
The transporters controller looks like this:
'use strict'; angular.module('mean.transporters').controller('TransportersController', ['$scope', '$routeParams', '$location', 'Global', 'Transporters', function ($scope, $routeParams, $location, Global, Transporters) { $scope.global = Global; $scope.create = function() { var transporter = new Transporters({ name: this.name, natl_id: this.natl_id, phone: this.phone }); transporter.$save(function(response) { $location.path('transporters/' + response._id); }); this.title = ''; this.content = ''; }; $scope.remove = function(transporter) { if (transporter) { transporter.$remove(); for (var i in $scope.transporters) { if ($scope.transporters[i] === transporter) { $scope.transporters.splice(i, 1); } } } else { $scope.transporter.$remove(); $location.path('transporters'); } }; $scope.update = function() { var transporter = $scope.transporter; if (!transporter.updated) { transporter.updated = []; } transporter.updated.push(new Date().getTime()); transporter.$update(function() { $location.path('transporters/' + transporter._id); }); }; $scope.find = function() { Transporters.query(function(transporters) { $scope.transporters = transporters; }); }; $scope.findOne = function() { Transporters.get({ transporterId: $routeParams.transporterId }, function(transporter) { $scope.transporter = transporter; }); }; }]);
In my views I call the list and create methods. They generate the above error
I got this from the angular docs for ng:areq though still can't figure what's going on
AngularJS often asserts that certain values will be present and truthy using a helper function. If the assertion fails, this error is thrown. To fix this problem, make sure that the value the assertion expects is defined and truthy.
Here's the view that calls the controller
public/views/transporters/list.html
:<section data-ng-controller="TransportersController" data-ng-init="find()"> <ul class="transporters unstyled"> <li data-ng-repeat="transporter in transporters"> <span>{{transporter.created | date:'medium'}}</span> / <h2><a data-ng-href="#!/transporters/{{transporter._id}}">{{transporter.name}}</a></h2> <div>{{transporter.natl_id}}</div> <div>{{transporter.phone}}</div> </li> </ul> <h1 data-ng-hide="!transporters || transporters.length">No transporters yet. <br> Why don't you <a href="/#!/transporters/create">Create One</a>?</h1> </section>
Transporters service code:
angular.module('transporterService', []) .factory('Transporter', ['$http', function($http){ // all return promise objects return { get: function(){ return $http.get('/api/transporters'); }, create: function(transporterData){ return $http.post('/api/transporters', transporterData); }, delete: function(id){ return $http.delete('/api/transporters/'+id); } }; }]);
解决方案I experienced this error once. The problem was I had defined angular.module() in two places with different arguments.
Eg:
var MyApp = angular.module('MyApp', []);
in other place,
var MyApp2 = angular.module('MyApp', ['ngAnimate']);
这篇关于错误:[NG:AREQ]从角控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!