angular2 routing - Angular 2 - Extract multiple variables from url -


i want extract multiple parameters url. suppose url

www.example.com/parent-component/2/list/child-component/5/list

i want extract parameters 2 , 5

the link on parent component is

[routerlink]="['/loggedin','warehouse','move-request',moverequest.id, 'issued-inventory',issuedinventory.id,'list']" 

in respective routes file doing this

{path:':move/issued-inventory',component:issueinventorycomponent, children : issued_inventory_routes} 

the child route file is

{path:':myid/list',component:listissueinventorycomponent}, 

in following component want access both variables move , myid

this.sub = this.activatedroute.params.subscribe((params : params) =>         {            this.moverequestid = params['move'];          }); 

on console moverequestid undefined doing wrong? how access variables?

router version :     "@angular/router": "^3.3.1" 

you should first retrieve parent route extract parent route parameter. before doing need router instance current route parent activatedroute.

constructor(private activatedroute: activatedroute, private router: router){  }  this.sub = this.activatedroute.params.subscribe((params : params) => {     //retrieve parent activated route     const parentroute = this.router.routerstate.parent(activatedroute);     this.moverequestid = params.params['move']; }); 

rather refer current activated route snapshot property, has reference parent route.

let move = this.activatedroute.parent.params['move']; 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -