angularjs - Unable to set default selected option in selection tag -


i have encountered issue angular.js 1.4.0. can't set default in select tag if use 'number' work if use 'string'. select statement hard code in view. initialize model in controller.

// not work, value passed 'number' $scope.colors = 2;

// work, value passed 'string' $scope.colors='2';

view/model:

<div ng-app="app">   <div ng-controller="mycontroller">     <select ng-model="colors">       <option value="1">red</option>       <option value="2">blue</option>       <option value="3">green</option>     </select>     <p>selected color: {{colors}}</p>     <div ng-switch="colors">       <p ng-switch-when="1"><span class="red-block"></span></p>       <p ng-switch-when="2"><span class="blue-block"></span></p>       <p ng-switch-when="3"><span class="green-block"></span></p>     </div> </div> 

controller:

angular.module('app', []).controller('mycontroller', function($scope) {    /* angular.js version 1.4.0 issue:        $scope.colors = 2; --> not work       $scope.colors = '2'; --> work        working on angular.js version 1.3.15    */    $scope.colors = 1; }); 

if use angular.js version 1.3.15, both 'number' , 'string' work.

note: angular version set in codepen 1.4.0 can see error.

http://codepen.io/joemalski/pen/yxqmko?editors=001

js:

$scope.options = [{ name: "a", id: 1 }, { name: "b", id: 2 }]; $scope.selectedoption = $scope.options[1]; 

html:

<select data-ng-options="o.name o in options" data-ng-model="selectedoption"></select> 

this leave "b" item selected.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -