67611: ExpressionChangedAfterItHasBeenCheckedError fix

This commit is contained in:
Kristof De Langhe
2020-01-16 14:47:37 +01:00
parent 010da52476
commit 3fd4ecbfc4

View File

@@ -1,4 +1,4 @@
import { filter, map, take } from 'rxjs/operators'; import { delay, filter, map, take } from 'rxjs/operators';
import { AfterViewInit, ChangeDetectionStrategy, Component, HostListener, Inject, OnInit, ViewEncapsulation } from '@angular/core'; import { AfterViewInit, ChangeDetectionStrategy, Component, HostListener, Inject, OnInit, ViewEncapsulation } from '@angular/core';
import { NavigationCancel, NavigationEnd, NavigationStart, Router } from '@angular/router'; import { NavigationCancel, NavigationEnd, NavigationStart, Router } from '@angular/router';
@@ -125,8 +125,11 @@ export class AppComponent implements OnInit, AfterViewInit {
} }
ngAfterViewInit() { ngAfterViewInit() {
this.router.events this.router.events.pipe(
.subscribe((event) => { // This fixes an ExpressionChangedAfterItHasBeenCheckedError from being thrown while loading the component
// More information on this bug-fix: https://blog.angular-university.io/angular-debugging/
delay(0)
).subscribe((event) => {
if (event instanceof NavigationStart) { if (event instanceof NavigationStart) {
this.isLoading = true; this.isLoading = true;
} else if ( } else if (