论证' myController'不是一个功能,未定义

时间:2016-06-26 10:32:32

标签: javascript angularjs angular angularjs-scope angularjs-controller

我试图在我的角应用程序中设置一些控制器,但我不确定为什么我不能让它们工作,因为我认为我使用的方法与我相似#&# 39;之前完成过。

我宣布了app.js文件:

[file writeToFile:filePath options:NSDataWritingFileProtectionNone error:nil];

然后controller.js文件包含以下内容:

'use strict';

var modules = [
    'app.controllers',
    'ngCookies',
    'ngResource',
    'ngSanitize',
    'ngRoute',
    'ui.router',
    'LocalStorageModule',
    'angular-loading-bar'
];

var app = angular.module('app', modules);

app.config(function($httpProvider) {
    $httpProvider.interceptors.push('authInterceptorService');
})

app.factory('forgotPasswordService', ['$http', function ($http) {

    var fac = {};

    fac.forgotPassword = function (forgotPasswordData) {
        return $http.post('/api/Account/ForgotPassword', forgotPasswordData)
    };

    return fac;

}])

app.factory('signUpService', ['$http', function ($http) {

    var signUpServiceFactory = {};

    signUpServiceFactory.saveRegistration = function (registration) {
        return $http.post('/api/account/register', registration);
    };

    return signUpServiceFactory;
}]);

我的html文件:

angular.module('app.controllers', [])
    .controller('signupController', [
        '$scope', '$window', 'signUpService',
        function($scope, $window, signUpService) {
            $scope.init = function() {
                $scope.isProcessing = false;
                $scope.RegisterBtnText = "Register";
            };

            $scope.init();
            $scope.IsLimitedCompany = null;
            $scope.registration = {
                Email: "",
                Password: "",
                ConfirmPassword: ""
            };

            $scope.signUp = function() {
                $scope.isProcessing = true;
                $scope.RegisterBtnText = "Please wait...";
                signUpService.saveRegistration($scope.registration).then(function(response) {
                    alert("Registration Successfully Completed. Please sign in to Continue.");
                    $window.location.href = "login.html";
                }, function() {
                    alert("Error occured. Please try again.");
                    $scope.isProcessing = false;
                    $scope.RegisterBtnText = "Register";
                });
            };
        }
    ]);

知道我错过了什么吗?

我收到此错误:错误:[ng:areq] Argument' signupController'不是一个功能,未定义

提前致谢,Laziale

1 个答案:

答案 0 :(得分:1)

您以错误的顺序包含了JS文件。

目前正是

<script src="/Angular/app.js"></script>
<script src="/Angular/controllers.js"></script>

因此你的app.js没有得到app.controllers的定义。

它应该像这个

<script src="/Angular/controllers.js"></script>
<script src="/Angular/app.js"></script>