错误:错误:areq Bad Argument

时间:2014-10-16 09:26:27

标签: angularjs angularjs-scope

我有一个控制器:

(function () {
    'use strict';
    angular.module("xPlat.controller", [])
    .controller('logInController', ['$scope', '$http', function ($scope, $http) {
        $scope.login = function () {
            var request = $http({
                method: "post",
                url: "http://localhost:4309/Account/Login",
                data: ""
            }) 
        }
    }])
})();

一个HTML文件:

<!DOCTYPE html>
<html>
<head>
    <title>Log In</title>
</head>
<body ng-app="xPlat">
    <div ng-controller="logInController">
        <input type="text" placeholder="UserName" />
        <input type="text" placeholder="Password" />
        <button ng-click="login()">Log In</button>
    </div>
    <!-- Cordova reference, this is added to your app when it's built. -->
    <script src="cordova.js"></script>
    <script src="scripts/platformOverrides.js"></script>

    <!-- CordovaToDoApp_AngularJS references -->
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular-resource.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular-route.js"></script>

    <script src="scripts/controllers/logInController.js"></script>
    <script src="scripts/index.js"></script>

</body>
</html>

当我构建并运行此应用程序时,我收到一条错误消息&#34;错误:[ng:areq]&#34;和链接,当我点击该链接时,我看到一条消息&#34;论证&#39; logInController&#39;不是一个功能,未定义&#34;。如何解决这个问题?感谢

2 个答案:

答案 0 :(得分:0)

你有一个带有xPlat.controller的xPlat moduel作为依赖吗?

angular.module ('xPlat', [xPlat.controller]); 

或者,您可能希望使用xPlat作为模块而不是xPlat.controller,在本例中为 上面的第3行应该是:

angular.module("xPlat", [])

如果可能,还要确保将角度升级到最新值(1.2.26)。在1.2.23中他们几乎没有毛刺。

答案 1 :(得分:0)

尝试这样:希望它能够发挥作用

var app=angular.module ('xPlat', [xPlat.controller]); 

app.controller("logInController", function () {
        alert('Done!!')
    });