Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a simple registration form page. The form page have a person_id field and drop down list name condition_code_1. Person_id field is mandatory field meanwhile the condition_code_1 drop down list is an optional field mean's that it is optional for user to be selected or not. The value of the drop down list is fetched through specialConds array that data are get from oracle db field.

I stored the value of drop down list in data array in Condition_code_1 controller.The problem is when i do not select the list and submitted the form, angularjs throws an error : Cannot read property 'condCode1' of null. How do i ignored the drop down list when it is not selected. Any help here.

1) Condition_code_1 list

  <select id = "condition_code_1"
          data-placeholder = "Please select"   
          ng-model         = "specialCond.condCode1"
          ng-options       = "t.condCode as t.condDesc for t in specialConds" chosen>
          <option value="">&nbsp;</option>
  </select>

2) Condition_code_1 Controller

 $scope.create = function () {
    var data = {};

    data.personId = $scope.person_id;
    data.conditionCode1 = $scope.specialCond.condCode1; 

    CondCodeSvc.create(data, function(res){
           jAlert('Create successfull');
    }, errSvc.errorHandler);                   
 };
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
157 views
Welcome To Ask or Share your Answers For Others

1 Answer

That's because data doesn't exist before you call $scope.create(), therefore is undefined, which means is not an object, which means it cannot have a property, thus javascript throws the error.

try:

var data = {};
$scope.create = function () {

    data.personId = $scope.person_id;
    data.conditionCode1 = $scope.specialCond.condCode1; 

    CondCodeSvc.create(data, function(res){
       jAlert('Create successfull');
    }, errSvc.errorHandler);                   
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...