2016-01-12 57 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

相关问题