2016-08-04 17 views
1

のプロパティ「ユーザーIDを」私はエラーしまっ読み取ることができませんTypeError例外:「例外TypeError:未定義のプロパティ 『ユーザーID』を読み込めません」未定義

を、これは私のコントローラ

.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> 

私はコードを実行します。 私はイオンフレームワークとビジュアルスタジオコードを使用しています。 あなたは何が間違ったiveが作られたか教えてくれますか? あなたの助けを借りて

+0

'datateman'は実行' simpan'のときに定義されていません。私はsimpanがどこからでも呼ばれているのを見ないのですか? –

答えて

3

まず、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" 
     }); 
+0

ああ、Aransありがとう、それは動作します – Borom1r

+0

汗@ Borom1r – AranS

関連する問題