Trying to figure out why OnPush
change detection strategy is not working In this demo.
If I understand correctly OnPush
change detection should be triggered when a property reference changes. and in order to ensure this a new array is set each time like this:
this.periodData$.subscribe((pd) => {
this.periodData = [...pd];
});
And the template that renders periodData
looks like this:
<div *ngFor="let p of periodData">{{p}}</div>
The periodData
is changed via the select control in the demo.
We can see that it is changing via the log, however the template is not updating. If change detection is set to default then it works.
Thoughts?
2
Answers
Ah - OK - I found the answer here. In short:
Use
ChangeDetectorRef
to manually trigger change detection after updatingperiodData
.