0

Am using ng-options to populate dropdown list, There are 3 dropdowns which are dependent on each other. If I select a particular option in Dropdown1, the other two drpdowns should appear. Then, if I select some values in that two dropdowns and without saving am changing the value in 1st dropdown the 2 dropdowns should get disappeared. Now the problem is that if I re-select the same option in Dropdown1 the values which I have selected previously are not refreshed.

<li class="col-sm-3">
    <p>Reason<b>*</b></p>
    <p>
        <select data-ng-model="note.reason" data-ng-options="option as option.value for option in reasons">
            <option style="display:none"  data-ng-model="note.reason" value="">Select Reason</option>
        </select>
    </p>
</li>
<li class="col-sm-3" ng-show="note.reason.value=='Intervention'">
    <p>Category<b>*</b></p>
    <p>
        <select data-ng-model="note.category"  ng-if ="note.reason" data-ng-options="option as option.value for option in categories">
            <option style="display:none" selected="selected" value="">Select Category</option>
        </select>
    </p>
</li>
<li class="col-sm-3" ng-show="note.reason.value=='Intervention'">
    <p>Tone<b>*</b></p>
    <p>
        <select data-ng-model="note.tone" ng-if ="note.reason" data-ng-options="option as option.value for option in tones">
            <option style="display:none"  value="">Select Tone</option>
        </select>
    </p>
</li>

I am using ng-if to do the same, earlier it was working properly when data-ng-model="reason", when data-ng-model is changed to note.reason, ng-if stopped working. Can you explain to me the problem in Detail.

TheSharpieOne
  • 25,646
  • 9
  • 66
  • 78

2 Answers2

0

You can either use ng-change as below

<select ng-change="note.tone='';note.category='';" data-ng-model="note.reason" data-ng-options="option as option.value for option in reasons">

Or put a $watch in the controller as below

$scope.$watch('note.reason', function(){
    $scope.note.tone="";
    $scope.note.category="";
}); 

Both will refresh the drop downs.

MaheshMG
  • 41
  • 3
0

Thanq,This is working Fine.

$scope.prvdNote = {};
$scope.show=function(){
  if(!angular.isUndefined($scope.prvdNote.prvdReason) && $scope.prvdNote.prvdReason.value=='Intervention'){
   return true;
  }else{
   $scope.prvdNote.prvdTone = undefined;
   $scope.prvdNote.prvdCategory = undefined;
   return false;
  }
  
    
 };
<li class="col-sm-3">
     <p>Reason<b>*</b></p>
     <p>
       
     <select data-ng-model="prvdNote.prvdReason" data-ng-options="option as option.value for option in reasons" ><option style="display:none"   value="" >Select Reason</option></select>

     </p>
    </li>

    <li class="col-sm-3" ng-show="show()" >
     <p>Category<b>*</b></p>
     <p>
      <select data-ng-model="prvdNote.prvdCategory"   data-ng-options="option as option.value for option in categories" ><option style="display:none" value="" >Select Category</option></select>
     </p>
    </li>
    <li class="col-sm-3" ng-show="show()"><p>Tone<b>*</b></p>
    <p>
      <select data-ng-model="prvdNote.prvdTone"  data-ng-options="option as option.value for option in tones" ><option style="display:none" value="" >Select Tone</option></select>
     </p>
    </li>