2016-07-25 3 views
1

버전 1.1.5에서 최신 1.5.8로 angularJS를 마이그레이션하려고하는데이 오류가 발생합니다. :AngularJS 마이그레이션 from v1.1.5에서 v1.5.8 인수 'Login.Controller'는 정의되지 않은 함수입니다.

angular.js:13920 Error: [ng:areq] Argument 'Login.Controller' is not a function, got undefined http://errors.angularjs.org/1.5.8/ng/areq?p0=Login.Controller&p1=not%20a%20function%2C%20got%20undefined

JS

var app = {}; 
app = angular.module('myApp', ['ngResource', 'ngRoute']) 

//Login Controller 
Login = { 
/** 
* Initializes the login page. 
*/ 
controller: function ($scope, $location, User) { 
    Login.initializeScopeVariables($scope); 
    Login.createScopeFunctions($scope, $location, User); 
}, 
initializeScopeVariables: function ($scope) { 
    $scope.$root.forgotPasswordUsername = null; 
}, 
createScopeFunctions: function ($scope, $location, User) { 
    $scope.reset = function() { 
     $scope.$root.filters = {}; 
     Login.resetForm($scope); 
    } 
    $scope.submit = function() { 
     Login.submitForm($scope, $location, User); 
    } 
    $scope.validate = function() { 
     if ($scope.loginForm.$valid) { 
      $('#submit-btn').linkbutton('enable'); 
     } else { 
      $('#submit-btn').linkbutton('disable'); 
     } 
    } 
    $scope.$root.submitPasswordReminder = function() { 
     if ($scope.$root.forgotPasswordUsername) { 
      mask(true); 
      User.sendPasswordReminder($scope.$root.forgotPasswordUsername).success(
       function (data) { 
        mask(false); 
        if (data.status == M2M.Response.ERROR) { 
         error(data.statusMessage); 
        } else { 
         info(Locale.get('passwordReminderSent')); 
         $scope.clearPasswordReminderForm(); 
        } 
       } 
      ).error(errorCallback); 
     } 
    } 

    $scope.$root.clearPasswordReminderForm = function() { 
     $('#forgot-password-window').window('close'); 
     $scope.$root.forgotPasswordUsername = null; 
    } 

    $(document).keypress(function (event) { 
     if (13 == event.keyCode) { 
      $scope.submit(); 
      $scope.$apply(); 
     } 
     if (27 == event.keyCode) { 
      $scope.reset(); 
      $scope.$apply(); 
     } 
    }) 
}, 

/** 
* Resets login form 
* 
* @param $scope 
*/ 
resetForm: function ($scope) { 
    $scope.username = ''; 
    $scope.password = ''; 
    $('input').removeClass('validatebox-invalid'); 
}, 
/** 
* Submits login form 
* 
* @param $scope 
* @param $location 
* @param User 
*/ 
submitForm: function ($scope, $location, User) { 
    if (!($scope.username && $scope.password)) { 
     return; 
    } 
    mask(true); 
    User.authenticate($scope.username, $scope.password).success(
     function (data) { 
      if (data.status == M2M.Response.ERROR) { 
       mask(false); 
       error(data.statusMessage); 
      } else { 
       location.href = 'main.html'; 
      } 
     } 
    ).error(errorCallback); 
} 

}

HTML

 <div class="login-area" ng-controller="Login.controller" style="width: 1300px; margin: auto"> 
     <form autocomplete="off"> 
      <div class="login-panel" ng-form name="loginForm" align="center"> 
       <table> 
        <tr> 
         <td><fmt:message key="username"/></td> 
         <td> 
          <input class="easyui-validatebox w140" type="text" name="username" 
            data-options="required:true" 
            ng-model="username" 
            ng-change="validate()" 
            required/> 
         </td> 
        </tr> 
        <tr> 
         <td><fmt:message key="password"/></td> 
         <td><input class="easyui-validatebox w140" type="password" name="password" 
            data-options="required:true" 
            ng-model="password" 
            autocomplete="off" 
            ng-change="validate()" 
            required/></td> 
        </tr> 
        <tr> 
         <td colspan="2"> 
          <a id="submit-btn" class="easyui-linkbutton" data-options="iconCls:'icon-ok',disabled: true" 
           ng-click="submit()"><fmt:message key="submit"/></a> 
          <a id="reset-btn" class="easyui-linkbutton" data-options="iconCls:'icon-undo'" 
           ng-click="reset()"><fmt:message key="reset"/></a></td> 
        </tr> 
       </table> 
       <div class="clr tac small"> 
        <a href="#" id="forgot-passwd" onclick="$('#forgot-password-window').window('open')"><fmt:message 
          key="login.forgotPassword"/></a> 
       </div> 
       <br> 
       <div class="clr tac"> 
        <fmt:message key="login.disclaimer"/> 
       </div> 
      </div> 
     </form> 
    </div> 

각도의 최신 버전에서 이것이 왜 발생하는지 알 수 없습니다.

코드를 변경해야합니까?

+0

여기서'app.controller'를 수행하는 부분은 어디입니까 –

+0

Dudette! 귀하의 로그인 컨트롤러는 어디입니까 ?? 당신은'app.controller ("loginCtrl", .., function() {}); –

+0

그래, 나도 전에도 이런 걸 본 적이 없지만 그 코드는 괜찮 았어. 'Login = { 컨트롤러 : function ($ scope, $ location, User) {...} ' – Margaret

답변

1

컨트롤러를 정의하는 방법입니다. Angular Documentation을 참조하십시오. 서비스입니다 which..err..component 알

myApp.controller('GreetingController', ['$scope', function($scope) { 
    $scope.greeting = 'Hola!'; 
}]); 

각도 요구하는 당신이 yourApp.controller 같은 모듈에 등록하도록 공장, 컨트롤러 등.

위의 예에서 GreetingController은 컨트롤러의 이름입니다. 귀하의 경우에는 loginController이됩니다. 콜백 함수의 모든 기능을 정의합니다.

function($scope,..){ 
    //code goes here. 
} 

여기에서 ...은 다른 종속성입니다.

난, 그냥 각도 1.5.x.에 따라 자신의 코드를 조정하는 것 작동 것 바라고 있어요


var app = {}; 
app = angular.module('myApp', ['ngResource', 'ngRoute']) 

//Login Controller 
app.Controller('LoginController', '$scope', '$location', 'User' function($scope, $location, User){ 
    $scope.initializeScopeVariables(); 
    $scope.createScopeFunctions(); 

     $scope.initializeScopeVariables= function() { 
       $scope.$root.forgotPasswordUsername = null; 
     } 

     $scope.createScopeFunctions= function() { 
      $scope.reset = function() { 
        $scope.$root.filters = {}; 
        $scope.resetForm(); 
      } 
      $scope.submit = function() { 
        $scope.submitForm(); 
      } 
      $scope.validate = function() { 
        if ($scope.loginForm.$valid) { 
          $('#submit-btn').linkbutton('enable'); 
        } else { 
          $('#submit-btn').linkbutton('disable'); 
        } 
      } 
      $scope.$root.submitPasswordReminder = function() { 
        if ($scope.$root.forgotPasswordUsername) { 
          mask(true); 
          User.sendPasswordReminder($scope.$root.forgotPasswordUsername).success(
            function (data) { 
              mask(false); 
              if (data.status == M2M.Response.ERROR) { 
                error(data.statusMessage); 
              } else { 
                info(Locale.get('passwordReminderSent')); 
                $scope.clearPasswordReminderForm(); 
              } 
            } 
          ).error(errorCallback); 
        } 
      } 

      $scope.$root.clearPasswordReminderForm = function() { 
        $('#forgot-password-window').window('close'); 
        $scope.$root.forgotPasswordUsername = null; 
      } 
      /** 
      * Resets login form 
      * 
      * @param $scope 
      */ 
      $scope.resetForm= function() { 
        $scope.username = ''; 
        $scope.password = ''; 
        $('input').removeClass('validatebox-invalid'); 
      }, 
      /** 
      * Submits login form 
      * 
      * @param $scope 
      * @param $location 
      * @param User 
      */ 
      $scope.submitForm= function() { 
        if (!($scope.username && $scope.password)) { 
          return; 
        } 
        mask(true); 
        User.authenticate($scope.username, $scope.password).success(
          function (data) { 
            if (data.status == M2M.Response.ERROR) { 
              mask(false); 
              error(data.statusMessage); 
            } else { 
              location.href = 'main.html'; 
            } 
          } 
        ).error(errorCallback); 
      } 
     } 
}); 
$(document).keypress(function (event) { 
     if (13 == event.keyCode) { 
       $scope.submit(); 
       $scope.$apply(); 
     } 
     if (27 == event.keyCode) { 
       $scope.reset(); 
       $scope.$apply(); 
     } 
}) 
오류가 발생하면 알려주세요.

+0

코드가 현재 1.1.5에서 작동하고 있다는 OP의 설명을 언급하지 않았습니다. 이는 마이그레이션 문제입니다. – Boaz

+0

@ 보아즈 알아. 그것은 다른 버전입니다. 그녀의 응용 프로그램의 한 부분을 수정하는 방법을 말하는 것은 아닙니다. 저는 Angular 1.5.x에서 컨트롤러에 대한 일반적인 아이디어를 제공합니다. 그녀는 많은 변화를 가져야 할 것입니다. –

+1

두 버전의 차이점을 설명하고 가능한 경우 최소한의 변경만으로 이전 버전에서 새 버전으로 마이그레이션하는 방법을 제안 할 수 있습니다. – Boaz

관련 문제