There are following workarounds of Angular Routing Parameters:
- Required Parameters
- Optional Parameters
- Query Parameters
- Navigation Extras
let's discuss 4rth one: Navigation Extras
This new method came after Angular 7.2.0 which represents the extra options used during navigation.
How to send parameters to another component from the current one?
constructor (private router : Router) {}
this.router.navigate(['employee'], { state:{ name:'Muhammad Awais' } })
How to get parameters in the destination routed component?
constructor (private router : Router) {
this.router.getCurrentNavigation().extras.state.name;
}
// This works only in the constructor, it will not work on ngOnInit
Top comments (0)