Angularjs Ng-model In Select Binding To Name Instead Of Value
AngularJS binds a scoped variable specified in ng-model (or data-ng-model) to an actual
Solution 1:
Never use ngRepeat to build select options, there is dedicated directive for this, ngOptions:
<selectclass="settings-select-box" name="LOCATION_UPDATE_FREQUENCY"
id="LOCATION_UPDATE_FREQUENCY"
data-ng-model="configurations.LOCATION_UPDATE_FREQUENCY"
data-ng-change="updateSelectList()"
data-ng-options="option.value as option.name for option in frequency">
</select>
ngModel has other benefits too: ability to bind to objects, no child scope per item.
Solution 2:
Change "default"
to ""
for {value: "default", name: "Select an option"}
To remove the extra blank option.
You can use ng-option on select too as follows:
<select
ng-options="item.value as item.name for item in frequency track by item.value"class="settings-select-box"
name="LOCATION_UPDATE_FREQUENCY"
id="LOCATION_UPDATE_FREQUENCY"
data-ng-model="configurations.LOCATION_UPDATE_FREQUENCY"
data-ng-change="updateSelectList()"></select>
Post a Comment for "Angularjs Ng-model In Select Binding To Name Instead Of Value"