Reputation: 21
Methods in Oninit function are not invoked second time when navigate back to the same page with same route.
Upvotes: 2
Views: 1247
Reputation: 694
Use this implementation method
import { ActivatedRoute } from '@angular/router';
constructor(
private routerActive:ActivatedRoute
) {}
ngOnInit() {
this.routerActive.paramMap.subscribe(paramMap => {
if (this.router.url === "/yourURL") {
// ***** This runs whenever your page is displayed ******
}
})
}
Upvotes: 2
Reputation: 15261
Routes are cached by default, it means you should subscribe to paramMap
and trigger loading in subscribe
callback, if you trigger loading from constructor or lifecycle method - it will not be invoked second time.
Upvotes: 1