Created
June 2, 2020 15:20
-
-
Save saurabh47/e30d4bdcfe39f838d6b618119d98c219 to your computer and use it in GitHub Desktop.
Angular2+ get Route data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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