AngularJS dropdown not showing selected value

前端 未结 4 1099
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-08 11:06

Am facing problem in displaying selected value in angular dropdown. it works when i give like this

$scope.selectedItem = $scope.items[1];

not w

4条回答
  •  失恋的感觉
    2021-02-08 11:32

    As explained in the other answers, while the two objects may have the same properties and values, they are two different objects so angular doesn't consider them to be equal.

    You can however use the track by expression in ng-options to specify a property which will decide equality:

    ng-options="item.name for item in items track by item.name"

    http://codepen.io/anon/pen/WbWMrp

提交回复
热议问题