How to get params url parent id from children
Since angular 5.2.x
there is another way to access parent params.
All you have to do is set config option paramsInheritanceStrategy to 'always'
like this:
RouterModule.forRoot(routes, {
paramsInheritanceStrategy: 'always'
})
With this config, you will have access to all ancestor routes params via prototypal inheritance, so you can get it directly from activated route:
this.activatedRoute.snapshot.params
You can use the ActivatedRoute
class from angular/router
import { ActivatedRoute, Router } from "@angular/router"
public activatedRoute: ActivatedRoute
this.activatedRoute.parent.params // return observable
if you want the static value, then ask for
this.activatedRoute.parent.snapshot.params // return static values
By using the attribute parent, you can access to all the parameters and queries from the parent component
You need to import ActivatedRoute from @angular/router:
import { ActivatedRoute } from "@angular/router";
Then in your constructor of AlbumsComponent you can grab that :id parameter like this:
let id = this.activatedRoute.parent.snapshot.params["id"]
Hope it helps!