【问题标题】:Error: [ng:areq] Argument 'xController' is not a function, got undefined错误:[ng:areq] 参数“xController”不是函数,未定义
【发布时间】:2015-10-10 12:31:51
【问题描述】:

我正在使用 Angular v1.4.2,并且不断收到“Error: [ng:areq] Argument 'accountRegisterCtrl' is not a function, got undefined”下面是我的控制器定义

(function(app) {

    'use strict';

    function accountRegisterCtrl($scope, $window) {

       //........

        $scope.previous = function () {
            $window.history.back();
        }
    }

    app.controller('accountRegisterCtrl', ['$scope', '$window', accountRegisterCtrl]);

}(angular.module('accountRegister')));

任何机构都可以提供帮助!

【问题讨论】:

  • 只需使用内联函数,您就可以解决问题。

标签: angularjs


【解决方案1】:

如果您在 HTML 视图或路由定义中拼错了控制器,通常会发生此错误:

<div data-ng-controller="accountRegisterCtl"> <!-- WRONG -->
    // ui stuff ...
</div>

这里 accountRegisterCtl 控制器在编译步骤中被调用,但它不存在,因为它拼写错误:accountRegisterCtrl 是正确的控制器名称。

<div data-ng-controller="accountRegisterCrtl"> <!-- CORRECT -->
    // ui stuff ...
</div>

或者你的controller.js没有注入你的index.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 2015-11-03
    • 2016-10-23
    • 2016-11-12
    • 2016-03-04
    • 2015-11-18
    • 2015-07-27
    相关资源
    最近更新 更多