Update:
showUpdatedItem(newItem){
let indexToUpdate = this.itemArray.items.findIndex(item => item.id === newItem.id);
this.itemArray.items[indexToUpdate] = newItem;
// some angular libraries require breaking the array reference
// to pick up the update in the array and trigger change detection.
// In that case, you can do following
this.itemArray.items = Object.assign([], this.itemArray.items);
}
Stackblitz Demo
Original Answer:
I have created this Plunker based on your example that updates the object equal to newItem.id
Here’s the snippet of my functions:
showUpdatedItem(newItem){
let updateItem = this.itemArray.items.find(this.findIndexToUpdate, newItem.id);
let index = this.itemArray.items.indexOf(updateItem);
this.itemArray.items[index] = newItem;
}
findIndexToUpdate(newItem) {
return newItem.id === this;
}