Let's say we have an array of objects:
ctrl.items = [Object, Object, Object]
Each object in the array follows this structure:
{id:1, item:"item", quantity:2}
These objects are displayed in the front-end using the following binding:
<div ng-repeat="item in ctrl.items">
<span ng-bind="item.item"></span>
<span ng-bind="item.quantity"></span>
</div>
When a specific id is received from the back-end and passed to a function called 'updateItem', like this:
updateItem(id)
The task is to update the object in ctrl.items
with a matching id
(specifically, increase the object's quantity
by 1). After retrieving the relevant item using:
self.item = $filter('filter')(self.items, {id: id}, true);
self.item.quantity = self.item.quantity + 1;
The main question is what steps to take next? (Considering that self.item is currently a variable. How can we replace the item inside ctrl.items
with self.item
?).