One possible solution to your problem might look like this:
1) You need to import NgZone
import { NgZone } from '@angular/core';
2) Add it to your constructor
constructor( ... private ngZone: NgZone ) {}
3) Add code that does the magic in your goTo
method
goTo(id) { this.router.navigate(['/detail', id]); if(id === 3) { this.ngZone.onMicrotaskEmpty.first().subscribe(this.ngAfterViewInit); } }
Thus, when you go to 3 pages of ngAfterViewInit
, the method will be executed after detecting changes
4) Remember to import the first
statement:
import 'rxjs/add/operator/first';
Here is an example of a plunger
source share