AngularJS dropdown not showing selected value

前端 未结 4 1095
佛祖请我去吃肉
佛祖请我去吃肉 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:37

    This is not an Angular feature/issue, it is a consequence of how object equality works in Javascript. This article does a fairly good job in explaining what is going on in a pretty concise way and gives some examples. Check out the source of lodash's isEqual method (it will take you to the definition of baseIsEqualDeep eventually) to see how what you are trying to achieve can be done in pure JS.

    In any case, I do not think there is an easy way to achieve this in Angular, you would have to re-write the way ng-options works and you probably do not want to go there...

提交回复
热议问题