zurfyx / angular-contents

Angular 5 Table of Contents that follows you while you scroll down
https://zurfyx.github.io/angular-contents
MIT License
40 stars 10 forks source link

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

Open blubberbo opened 5 years ago

blubberbo commented 5 years ago

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