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" />- ✓Correct answer: The array was mutated, so the input reference is the same and the OnPush child is not marked for check
- 2OnPush components can't receive arrays as inputs
- 3
pushis not allowed in Angular components
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.