javascript - How to use ng-options in angularjs -


the select element not bound expected.

html:

<select ng-model="selectedpage"   ng-change="showpageresult();" ng-options="o o in pagenumbers"> </select> 

ctrl.js:

function bindpagenumbers() {                 $scope.pagenumbers = [];         (var = 1; <= 2) ; i++) {             $scope.pagenumbers.push(i);         }           } 

output:

<option value="0"label="1">1</option> <option value="1" label="2">2</option> 

if put $scope.pagenumbers.push(i.tostring());, output

<option value="?"label=""></option> <option value="0" label="1">1</option> <option value="1" label="2">2</option> 

expected:

<option value="1">1</option> <option value="2">2</option> 

what should done desired o/p : http://jsfiddle.net/s222904f/

check it: http://jsfiddle.net/khwuv4lj/

per answer here, empty option exists because

ng-model="selectedpage" 

line binds empty string. can avoid setting default value if select in scope.

edit: plnkr updated fix op's comment.

enter image description here


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -