I am trying to get drop downs to only populate if the drop down above them has something selected. I had someone point me in the right starting direction with something like this.
<select class="selectLevel0" ng-model='scope1' ng-change='scope1Change()'
ng-options='obj.name for obj in array track by obj.id'>
</select>
<select class="selectLevel1" ng-model="scope2" ng-change='scope2Change()'
ng-options='obj.name for obj in array2 track by obj.id' ng-hide='!scope1'>
</select>
<select class="selectLevel2" ng-model="scope3" ng-change='scope3Change()'
ng-options='obj.name for obj in array3 track by obj.id' ng-hide='!scope2'>
</select>
<select class="selectLevel3" ng-model="scope4" ng-change='scope4Change()'
ng-options='obj.name for obj in array4 track by obj.id' ng-hide='!scope3'>
</select>
<select class="selectLevel4" ng-model="scope5"
ng-options='obj.name for obj in array5 track by obj.id' ng-hide='!scope4'>
</select>
This is fine for the first round - the drop downs below will not populate until the previous one has something selected. The tricky part is I'm trying to figure out if say I have selected all the way down to the 5th one and I go an reselect the 2nd level one. I then want the third level to show up and 4-5 to disappear. I was thinking maybe something like ng_show="!scope2 || !scope3" (or something similar where i pass multiple arguments), but I cannot seem to get something like this working in angular. Is there a better way of dealing with this?
I would probably try avoid repeating by rearranging the data and tweak the logic a bit. I would just have one select with
ng-repeat
and my source data will be a2D
array.Example:-
Then i would just keep an array to store respective models:-
Then have just one
changehandler
for all of them, which currently pass index you could even pass data.And finally my markup would just be:-
Demo