Angular · Middle · Question 2 of 75

Why doesn't this OnPush child update after the parent runs addItem()?

// parent
items = [{ id: 1 }];
addItem() { this.items.push({ id: 2 }); }
// template: <app-list [items]="items" />

Explanation

OnPush compares inputs by reference. Create a new array (this.items = [...this.items, item]) or keep the list in a signal and update it immutably.

Further reading

Problem with a question

Angular · Middle · question 2

Test yourself

Take the Angular · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz