The chart is not getting shown when page is loaded

πŸ‘:0

It’s because ngAfterViewInit is called after change detection is completed and the view has already been build. When you click on same label you execute new change detection cycle.

You can try to add this line of code after new Chart(), where cd is ChangeDetectorRef injected in constructor.

setTimeout(() => {

        this.cd.markForCheck();

    });

which will mark this component as a dirty for change detection.

Leave a comment