angular-contents icon indicating copy to clipboard operation
angular-contents copied to clipboard

*ngFor loop causes 'changed after it was checked' error

Open blubberbo opened this issue 6 years ago • 0 comments

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();
  }

blubberbo avatar Apr 13 '19 04:04 blubberbo