javascript - Add two extra options to a select list with ngOptions on it -
i have bunch of select lists , i'm trying add "none" , title option them. code looks so:
<select ng-options="value.name value in values" ng-model="selection"> <option value="" disabled>{{title}}</option> <option value="">none</option> </select>
for right now, cannot add them data trying find way working. when load them first time, "none" option not there. title there , works intended, seems cannot add 2 blank entries select list.
the easiest way have "none" option added data it's not possibility me. there proper way achieve want?
that's correct, can have 1 hard-coded element. <option ng-repeat>
can technically done, method cleanly supports binding strings, kludgey bind objects, you're doing.
you can't add "none" data, can next best thing: prepend array ng-options iterating across, using filter:
app.filter('addnone', function () { return function(input) { var newarray = input.slice(0); //clone array, or you'll end new "none" option added "values" array on every digest cycle. newarray.unshift({ name: "none" }); return newarray; }; })
then use filter this:
<select class="form-control" ng-options="value.name value.name value in filter.values | addnone" ng-model="filter.selected" ng-change="gosearch()"> <option value="" disabled>{{filter.name}}</option> </select>
Comments
Post a Comment