2016-01-12 49 views
0

類錯誤產生的未定義錯誤的性質:無法讀取瀏覽器 console error ..我正在試圖保存表單的任何信息而產生未定義錯誤的性質和它在console.If產生這個錯誤我輸入所有的細節和保存表單,然後沒有錯誤生成..作爲一個新手我無法追查它出錯哪裏。下面是HTML和控制器。可以幫助我追蹤錯誤..類型錯誤:無法讀取控制檯

(function() { 
    'use strict'; 

    angular 
     .module('app') 
     .controller('userSaveMunitOperatorCtrl', userSaveMunitOperatorCtrl); 

    userSaveMunitOperatorCtrl.$inject = ['$scope', '$rootScope','ngDialog', 'userSvc']; 

    function userSaveMunitOperatorCtrl($scope, $rootScope,ngDialog, userSvc) { 
     $scope.name = 'userSaveMunitOperatorCtrl'; 

     $scope.regularExpression = /^[a-zA-Z0-9]*$/; 
     $scope.onSaveChanges = function (options) { 
      $scope.errorMessage = ''; 
      $scope.saveMunitOperatorForm.$setPristine(); 
      if ($scope.user.mUnitPassword && $scope.user.mUnitPasswordConfirm) { 
       if ($scope.user.mUnitPassword === $scope.user.mUnitPasswordConfirm) $scope.saveMunitOperatorForm.$setValidity("confirm", true); 
       else $scope.saveMunitOperatorForm.$setValidity("confirm", false); 
      } 
      if ($scope.saveMunitOperatorForm.$valid) { 
       var mUnitData = { userId: '', mUnitOperatorName: '', mUnitPassword: '' }; 

       mUnitData.userId = $rootScope.currentUser.id; 
       mUnitData.mUnitOperatorName = $scope.user.mUnitOperatorName; 
       mUnitData.mUnitPassword = $scope.user.mUnitPassword; 

       userSvc.saveMUnitOperator(mUnitData).then(function (response) { 
        $rootScope.$broadcast("SaveMunitOperator", response); 
        $rootScope.$broadcast("refresh_MUnit", { dataItem: JSON.stringify(mUnitData.mUnitOperatorName) }); 

        if ($scope.closeThisDialog) 
         $scope.closeThisDialog('confirm'); 

        ngDialog.openConfirm({ 
         template: 'messageDialogId', 
         className: 'ngdialog-theme-default', 
         data: { 
          'message': $rootScope.$translate.instant("Maintenance unit info saved successfully.") 
         } 
        }); 
       }, 
        function (error) { 
        if (error) { 
         if (error.message.indexOf(':') >= 0) { 
          var errorMessage = error.message.split(':'); 
          $scope.errorMessage = errorMessage[1]; 
         } 
         else { 
          $scope.errorMessage = error.message; 
         } 

        } 
       }); 
      } 
     }; 

    }; 


})(); 
<div class="row pt bd1-top"> 
      <button type="submit" ng-click="onSaveChanges()" class="btn btn-labeled btn-green mr pull-right" data-qaid="munit-text-savemu-save"> 
       <span class="btn-label"> 
        <i class="fa fa-check"></i> 
       </span>{{'Save Changes' | translate}} 
      </button> 

回答

0

您必須聲明$scope.user第一之前使用它作爲一個模型

像這樣

$scope.user = {}; 
+0

我應該在哪裏聲明它到底是什麼? – Atchu

+0

位於'$ scope.name'下方或上方的控制器開頭@Atchu –

+0

Thanks @ Anik Islam Abhi – Atchu

相關問題