How To Get Both Parent And Child Params Data In Angular Router

Here we show you how easy it is to get the Angular 7 activated route params with RxJs combineLatest. First import combineLatest operator, combinning observable.

1
    import { Observable, Subscription, combineLatest } from 'rxjs'; 

Then , in our component class, we need to add the activatedRoute service class and subscribe to it. constructor(private _route: ActivatedRoute){} Now that we have the activatedRoute class in _route Lets combine the route parent and route child observables and subscribe to return the values.

1
2
3
this.sub_route = combineLatest( this._route.parent.params, this._route.params).subscribe( ([parent, child]) => { 
console.log(parent) // prints out parent key and value console.log(child) // Prints out child key and value 
});

That's it!. We welcome any suggestions or better way to do this!

Related Posts

0 Comments

12345

    00