本文介绍了错误:[NG:AREQ]从角控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个长镜头,但有没有人见过这个错误?我想加上'转运'使用前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 =转运;
        });
    };
}]);

在我的意见我所说的列表,并创建方法。它们所产生的上述错误

我得到这个从虽然还是想不通这是怎么回事

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]从角控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 19:10