AngularJS Select list has a blank item -
i have few select lists on page 1 of them works fine rest of them have blank item @ top of options list.
this works
<td> <select data-ng-model="c.resultoptionid" ng-change="checkresult(c)"> <option value="" selected>--select option--</option> <option data-ng-repeat="opt in c.resultoptions" value="{{opt.value}}">{{opt.text}}</option> </select> </td>
this has blank item
<td> <select data-ng-model="c.equipmentid"> <option value="" selected>--select equipment--</option> <option data-ng-repeat="eq in c.equipment" value="{{eq.value}}">{{eq.text}}</option> </select> </td>
the html generated select list item is
<td> <select data-ng-model="c.equipmentid" class="ng-pristine ng-valid ng-not-empty ng-touched"> <option value="? number:0 ?"></option> <option value="" selected="">--select equipment--</option> <!-- ngrepeat: eq in c.equipment --> <option data-ng-repeat="eq in c.equipment" value="2" class="ng-binding ng-scope">eq-001</option> <!-- end ngrepeat: eq in c.equipment --> </select> </td>
i'm new angularjs i've read should work. have checked data returned api call , correct there no unexpected items.
thanks
if use ng-repeat generate options, documentation indicates, bound value is, always, string.
but value stored in ngmodel (c.equipmentid
) number. you're telling angular: here's list of options values, strings, , please select, among string values, 1 equal number. since string never equal number, angular generates additional option.
so, usual, use ng-options generate options:
<select data-ng-model="c.equipmentid" ng-options="eq.value eq.text eq in c.equipment"> <option value="">--select equipment--</option> </select>
and make sure c.equipmentid
contains 1 of proposed equipment values, or null or undefined.
Comments
Post a Comment