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:

enter image description here

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.

  1. 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", }];

  2. 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

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -