angular-contents
angular-contents copied to clipboard
*ngFor loop causes 'changed after it was checked' error
I have the following code:
<li *ngFor="let thing of things">
<a [href]="utilitiesService.convertEndpointToAnchorLink(thing.name)" contentsLink pageScroll>{{
thing.name
}}</a>
</li>
but it gives me the Expression has changed after it was checked error - I have narrowed down the cause being the contentsLink attribute. Implementing the following in my component took the error away, but I was wondering if there is a more proper way this could be handled?
constructor(private cd: ChangeDetectorRef) {}
ngAfterViewInit() {
this.cd.detectChanges();
}