参数不是aNaNunction,在Controller上未定义

时间:2016-11-07 00:54:20

标签: angularjs controller angular-controller

所以我收到了这个错误,而且我一直在查看其他问题,但没有任何效果。

这是我宣布我的模块的地方:

(function () {
    'use strict';
    var app = angular.module('PaymentManagementApp', ['ngRoute', 'ngStorage', 'ngMessages', 'ngMaterial']);
    app.config(function ($routeProvider) {

        $routeProvider

        .when('/login', {
            templateUrl: 'app/components/login/login.html',
            controller: 'LoginController'
        })

})();

这是我得到错误的控制器' LoginController不是aNaNunction,未定义'

(function () {
    'use strict';
    angular
        .module('PaymentManagementApp')
        .controller('LoginController', function ($scope, $location) {

            $scope.processLogin = processLogin;

            function processLogin() {
                return;
            };


        })
})();

和html

<div id="login" class="image-content-layout" layout="row" layout-sm="column">

    <div class="background" style="background-image: url('assets/img/login.png');" flex></div>

    <div class="content" flex-md="70" flex-gt-md="40">
        <div class="wrapper">

            <h1 class="md-display-2 title">Iniciar sesión</h1>

            <form name="login">

                <md-input-container>
                    <label>Email</label>
                    <input required name="email" type="email" ng-model="email">

                    <div ng-messages="login.email.$error" ng-if="login.email.$touched">
                        <div ng-message="required">Debes ingresar tu email</div>
                        <div ng-message="email">El email no es válido</div>
                    </div>
                </md-input-container>

                <md-input-container>
                    <label>Contraseña</label>
                    <input required name="password" type="password" ng-model="password">

                    <div ng-messages="login.password.$error" ng-if="login.password.$touched">
                        <div ng-message="required">Debe ingresar una contraseña</div>
                    </div>
                </md-input-container>


                <p class="md-body-1 form-error">{{ formError }}</p>


                <div class="md-actions" layout="row">
                    <span flex></span>
                    <md-button href="#/signup" class="signup md-raised">Registarse</md-button>
                    <md-button type="submit" ng-click="processLogin()" class="md-primary md-raised login">Iniciar sesión</md-button>
                </div>
            </form>

            <div class="full-page-overlay" http-loader>
                <div layout="row" layout-sm="column" layout-align="space-around">
                    <md-progress-circular md-mode="indeterminate"></md-progress-circular>
                </div>
            </div>

        </div>
    </div>
</div>

我该怎么办才能修复它?

1 个答案:

答案 0 :(得分:-1)

您要定义angular.module('PaymentManagementApp')两次。

改变这个:

angular
        .module('PaymentManagementApp')
        .controller('LoginController', function ($scope, $location) {...}

为:

app.controller('LoginController', function ($scope, $location) {...}