How can I make the binding works for object properties. For example in my controller I have:
$scope.reviews = {
rating_summary: 4,
items: [ { title: 'A Title'}, etc... ]
}
And in my view:
<li ng-repeat="review in reviews.items">
Now, whenever i change the reviews variables in the controller, nothing is updated:
$scope.reviews = [new updated reviews]
Probably beacause angular is listening for changes on the old reference of $scope.reviews.
There are two solutions for the binding to work, but both are not very clever:
- Attach the items to the scope directly, so it would be
$scope.items = $scope.reviews.items, Now whenever the items are changed they would be updated. - User angular.copy to keep the destination reference, so
angular.copy({items: []}, $scope.reviews);
Are there any other solutions to accomplish this other than the above.