javascript - Angular: Getting error while using ng-option -
i have schema:
teams: [ { id: 1, name: "spain" }, { id: 2, name: "germany" } ]
now have select element:
<select ng-model="betschema.winnerid" ng-options="team.name team in teams track team.id"> <option value="-1">tie</option> </select>
the betschema
object looks (as default):
{ winnerid: -1 }
here result see:
the problems are:
1. can't see tie option, , there 1 mysteries "blank" option (the first @ top). 2. when betschema
looks this:
{ winnerid: 2 }
i expecting see germany option selected.
what doing wrong?
see fiddle: http://jsfiddle.net/mn4sh/4/
there couple of things.
when using ng-options angular going overwrite option tags have add model such:
scope.teams = [{ id: -1, name: "tie" }, { id: 1, name: "spain" }, { id: 2, name: "germany", }];
- second, can use track using "as" work in context: https://docs.angularjs.org/api/ng/directive/select. can use obj.datatobestoredinmodel obj.labelofdata obj in objlist id ng-options.
Comments
Post a Comment