TypeError:无法读取属性'userid'的未定义
TypeError: Cannot read property 'userid' of undefined
我得到错误"TypeError:无法读取未定义的的属性'userid'"
这是我的控制器
.controller('tambahTemanCtrl',function($scope,$ionicPopup,temanService){
$scope.showAlert = function(msg) {
$ionicPopup.alert({
title: msg.title,
template: msg.message,
okText: 'Ok',
okType: 'button-positive'
});
};
$scope.simpan = function (){
if (!$scope.datateman.userid){
$scope.showAlert({
title: "Information",
message: "UserID cant be blank"
});
else{
var data = {
Userid: $scope.datateman.userid,
Address: $scope.datateman.address,
Employeeid: $scope.datateman.employeeid,
Email: $scope.datateman.email,
Phoneno: $scope.datateman.phoneno,
Password: $scope.datateman.password,
Division: $scope.datateman.division,
Leavebalance: $scope.datateman.leavebalance
};
var dataCollection = [];
for(var item in data){
if(data.hasOwnProperty(item)){
dataCollection.push(data[item]);
}
}
var DTO = {
Value: dataCollection.join('|')
};
//do not use success. its obsolete
temanService.create(DTO).then(function(response){
},function(response){
//error
});
}
};
});
这是我的html
<ion-header-bar class="bar-positive">
<h1 class="title">Add User</h1>
</ion-header-bar>
<ion-content class="padding">
<form>
<ion-list>
<label class="item item-input">
<input type="text" ng-model="datateman.userid" placeholder="UserID">
</label>
<label class="item item-input">
<input type="text" ng-model="datateman.fullname" placeholder="Fullname">
</label>
<label class="item item-input">
<input type="text" ng-model="datateman.password" placeholder="Password">
</label>
</ion-list>
<div class="spacer" style="height: 5px;"></div>
<button class="button icon ion-person-stalker button-balanced button- block" ng-click="simpan();"> Save</button>
</form>
</ion-content>
它发生在我运行代码的时候。我使用的是ionic框架和visualstudio代码。你能告诉我我做错了什么吗?感谢您的帮助
在检查其属性的有效性之前,应首先初始化datateman
对象。像这样:
$scope.datateman = {};
$scope.simpan = function (){
//the interpreter looks for 'datateman' object in order to check for 'userid' existence
if (!$scope.datateman.userid){
$scope.showAlert({
title: "Information",
message: "UserID cant be blank"
});
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- this.userId 在 Meteor.publish 中返回未定义
- 在Meteor.js中,为什么this.userId==未定义
- 流星userId存在,但用户未定义
- TypeError:无法读取属性'userid'的未定义
- ajax和php错误:未定义的索引:在我的例子中是userid