angularjs select showing non filtered selected -


i'm ran across following found strange. i'm not blocked curious if knew. when use hasownproperty select option, shows value (a2f0c7) not in dropdown selected.. can share why happening? here jsfiddle:

http://jsfiddle.net/stampyny/2oeo8of9/1/

<div ng-controller="testctrl">     <select>         <option ng-repeat="(k,v) in items" ng-show="v.hasownproperty('test')" value="{{k}}">{{k}}</option>     </select> var app = angular.module('app', []);  function testctrl($scope) {     $scope.items = {                  'a2f0c7':{'secid':'12345', 'pos':'a20'},                  'c8b3d1':{'pos':'b10'},                  'wam':{'test': 1, 'pos':'b10'}                }; } 

thank you!

in angularjs, when add "ng-show={{expression}}", expression validated (either true or false) , add style "display: none;" respectively. result, have rendered in html:

<select>     <!-- ngrepeat: (k,v) in items -->     <option ng-repeat="(k,v) in items" ng-show="v.hasownproperty('test')" value="a2f0c7" class="ng-scope ng-binding" style="display: none;">a2f0c7</option>     <option ng-repeat="(k,v) in items" ng-show="v.hasownproperty('test')" value="c8b3d1" class="ng-scope ng-binding" style="display: none;">c8b3d1</option>     <option ng-repeat="(k,v) in items" ng-show="v.hasownproperty('test')" value="wam" class="ng-scope ng-binding">wam</option> </select> 

with style added, value won't showed in drop down box, default first value selected html select tag. that's reason why see value (although shouldn't).

to fix this,simply update code adding ng-selected:

<select>     <option ng-repeat="(k,v) in items" ng-show="v.hasownproperty('test')" ng-selected="v.hasownproperty('test')" value="{{k}}">{{k}}</option> </select> 

Comments