Let's say I have a simple array of texts:
textContent = [
{text: 'good morning'},
{text: 'lovely day'},
{text: 'for debugging'},
]
I render a simple component for each, passing in the text item as input:
<app-text *ngFor="let text of textContent" [text]="text"></app-text>
The text component renders the text, with ngModel:
<textarea [(ngModel)]="text.text"></textarea>
I'm also logging on DoCheck:
ngDoCheck() {
console.log(this.text.text, ' has been checked')
}
When I enter something into one textarea, all other components' DoCheck is fired.
good morning has been checked
lovely days has been checked
for debuggings has been checked
This happens even when OnPush is used for change detection.
Question: Why do changes made to one component's data trigger the entire tree to be checked?
(It's not a problem with a handful of components, but with a larger tree, I'm dropping frames).
I actually noticed that even components on a completely separate content tree have their 'doCheck' also fired.
Is there a way to prevent this from happening, or am I missing something else entirely?