1

I want to extract multiple parameters from url. Suppose the url is like

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

I want to extract the parameters 2 and 5

The link on parent component is

[routerLink]="['/loggedIn','warehouse','move-request',moveRequest.id, 'issued-inventory',issuedInventory.id,'list']"

In the respective routes file i am doing this

{path:':move/issued-inventory',component:IssueInventoryComponent, children : ISSUED_INVENTORY_ROUTES}

The child route file is

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

In the following component i want to access both variables move and myid

this.sub = this.activatedRoute.params.subscribe((params : Params) =>
        {
           this.moveRequestId = params['move'];

        });

On Console the moveRequestId is undefined What am i doing wrong? How to access those variables?

Router Version :     "@angular/router": "^3.3.1"
1
  • What does the ISSUED_INVENTORY_ROUTES look like? Commented Apr 14, 2017 at 16:29

1 Answer 1

2

You should first retrieve parent route to extract parent route parameter. But before doing that you need the router instance to get 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 you could just refer to current activated route snapshot property, it already has reference to parent route.

let move = this.activatedRoute.parent.params['move'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.