I have a parent Component which updates a every second its array myValue
. In a child component I want to create a chart which uses this array as data and update
You can find detailed explanations about that exception in this article. One technique to eliminate the exception is to force change detection with ChangeDetectorRef.detectChanges
:
export class ValueChartComponent implements AfterViewInit {
constructor(private cd: ChangeDetectorRef) { }
ngAfterViewInit(): void {
...
this.cd.detectChanges();
}
...
}
An alternative technique is to run the handler code asynchronously with setTimeout
:
export class ValueChartComponent implements AfterViewInit {
ngAfterViewInit(): void {
setTimeout(() => {
...
});
}
...
}