AngularJS dropdown not showing selected value

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

    In angular, Arrays and objects are passed by reference while strings, numbers and booleans are passed by value. So, angular interprets $scope.items[1] and { name: 'two', age: 27 } as two different objects. That's why your binding fails when you do $scope.selectedItem = { name: 'two', age: 27 }; directly and find it in '$scope.items'.

提交回复
热议问题