类型错误:无法读取浏览器 console error中生成的未定义错误的属性。我正在尝试使用任何信息保存表单,并在控制台中生成此错误。如果我输入所有详细信息并保存然后表示没有错误产生......作为一个新手,我无法追踪它出错的地方。下面是html和controller.Can有人帮我跟踪bug ..
(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 :(得分:0)
在将$scope.user
用作模型之前,您必须先声明$scope.user = {};
喜欢这个
WRITE_EXTERNAL_STORAGE