i am trying to update a part of an ng-repeat that has an nested ng-repeat inside, like this example:
<div ng-repeat="product in products">
<div ng-repeat="color in product.colors"></div>
</div>
the information comes from a combined array.
Array colors
Array products
and is merged into one array that looks like this:
{
product:"car",
brand:"volvo",
colors: {
front: "red",
roof: "yellow",
};
how would i be able to update the $scope.colors
and with that see the effect of the update in the ng-repeat
appear (add another color) without updating the complete $scope.products
of course, that will rebuild the whole thing
how would i be able to update the
$scope.colors
and with that see the effect of the update in theng-repeat
Use angular.copy
:
angular.copy(new_object, $scope.colors);
For more information, see
alright, instead of updating the actual scope, i added 'track by product.ID'
ng-repeat="product in products track by product.ID"
this prevents the complete structure rebuilding each time and now when i update the colors array and reinitiate the products scope it updates just colors
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.