I am trying to get the parent route parameters in a lazy loaded component of the route, however using activatedRoute.parent.params doesn't seem to work? I have a snippet that really works, but it involves using the "magic" array index number to retrieve the value ....
Why is this so, and is there a cleaner method in which I do not need to retrieve the value of the array ( this.activatedRoute.pathFromRoot[1] )?
I have the following route where I lazy load the module:
parent.route
routes:Routes = [ { path: "dashboard/:id", component: dashboard.DashboardComponent, canActivate: [guard.LoggedInGuard], children: [ { path: "my-dock", loadChildren: 'path/child.module#Child' } ] } ];
Then in the default component for child.module I have the following:
child.component
ngOnInit() { this.activatedRoute.pathFromRoot[1].params.subscribe((params: Params) => { console.log(params); // returns {id: "123456789"} }); this.activatedRoute.parent.params.subscribe((params: Params) => { console.log(params); // returns {} }); }
Why can't I use this.activatedRoute.parent.params to get the id parameter?
angular typescript
Zze
source share