Skip to content

Instantly share code, notes, and snippets.

@saurabh47
Created June 2, 2020 15:20
Show Gist options
  • Save saurabh47/e30d4bdcfe39f838d6b618119d98c219 to your computer and use it in GitHub Desktop.
Save saurabh47/e30d4bdcfe39f838d6b618119d98c219 to your computer and use it in GitHub Desktop.
Angular2+ get Route data
ngOnInit(): void {
this.router.events.pipe(
filter((event) => event instanceof NavigationEnd),
map(() => this.activatedRoute),
map((route) => {
while (route.firstChild) route = route.firstChild;
return route;
}),
filter((route) => route.outlet === 'primary'),
mergeMap((route) => route.data))
.subscribe((event) => console.log('Data',event));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment