javascript - Bind one attribute of an array of ng-options -
javascript - Bind one attribute of an array of ng-options -
i have next array:
[{code: "af", name: "afghanistan"}, {code: "za", name: "south africa"}, {code: "al", name: "albania"}]
i have select , bind ng-model on code attribute of selected object , not whole object. on other hand, select display name (and not code). in addition, if set ng-model code, pre-select name in selection.
i tried next (jade)
select(ng-model='mycountry', ng-options='country.name country in countries track country.name')
here ng-model gets whole object (mycountry = {code: "af", name: "afghanistan"}) , not code (mycountry = "af")
is possible that?
you can use:
<div> <select ng-model="country" ng-options="country.code country.name country in countries"></select> selected country (ng-model): {{country}} </div>
country.code
- used ng-model
attribute.
country.name
- used display item in select.
see demo here.
and if want set select alternative pre-selected value utilize country
model supply value.
javascript angularjs ng-options
Comments
Post a Comment