Tuesday, 15 July 2014

angularjs - Default value for select box preselected on page open -



angularjs - Default value for select box preselected on page open -

let's have array of colors.

i want create select box array default first item array preselected.

here's code seek use, fails:

<select ng-model="test" ng-init="colors[0]" ng-options="color color in colors"></select>

this anyway gives me blank selection box default, values apear when select something.

here's plunker demo: http://plnkr.co/edit/y0o61u49hby9evp7xrxi?p=preview

edit: in actual code have lot of selectionboxes created ng-repeat directive. solution (from @diryboy) manually setting scope.test outside select tag not preferable.

looks changing line 23 next works

$scope.test = $scope.colors[0];

angularjs

No comments:

Post a Comment