while changing the routes to homepage, javascript and jquery code is not loading in Angular 5
here is an angular way
export class PagesComponent implements OnInit, OnDestroy {
routerSubscription: any;
constructor(private router: Router) {}
ngOnInit() {
this.recallJsFuntions();
}
/**
* @description when we navigate from one page to another `scope of js funtions`
* finished so we have to call it again.
*/
recallJsFuntions() {
this.routerSubscription = this.router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe(event => {
$.getScript('/assets/js/common.js');
});
}
ngOnDestroy() {
this.routerSubscription.unsubscribe();
}
}