javascript - AngularJS not binding to numeric value in select list -


i have existing select tag existing option tags, 1 marked "selected", example:

<div class="form-group">   <label class="control-label">test</label>   <select ng-model="vm.testnumber">     <option>choose...</option>     <option value="1">one</option>     <option value="2">two</option>     <option value="3" selected>three</option>   </select>   <p class="help-block">{{vm.testnumber}}</p> </div> 

angular binding model correctly , spits out "3" in block when page loads, option 3 not selected. binds , shows 3 selected if use text value attributes on each option, not when it's numerical value. instead inserts option @ top of select list:

<option value="? number:3 ?"></option> 

what doing wrong?

from angular doc

note value of select directive used without ngoptions string. when model needs bound non-string value, must either explicitly convert or use ngoptions specify set of options. because option element can bound string values @ present.

if change code below code snippet, don't need explicit string conversions.

 <select ng-model="vm.testnumber" ng-options="item.value item.label item in [{label: 'one', value: 1}, {label: 'two', value: 2}]">     <option value="">choose...</option>   </select> 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -