Jackie
Jackie

Reputation: 23477

How do I get parameter from child route

I have the following plunker What I would expect is to hit the second link and see Angular 1234 thanks to the parameter I have in my child config...

const TWO_ROUTES = [
    {
        path: "test/:id",
        component: ChildComponent
    }
];

What I actually see is Angular undefined. What am I missing? How do I access the param in the child route?

Upvotes: 1

Views: 115

Answers (1)

Stefan Svrkota
Stefan Svrkota

Reputation: 50623

Instead of this.route.params['id'], it should be:

ngOnInit(){
    this.name = `Angular ${this.route.params.value['id']}`;
}

You can also use:

ngOnInit(){
    this.name = `Angular ${this.route.snapshot.params['id']}`;
}

Check official Angular docs for more info about Routing & Navigation.

Upvotes: 1

Related Questions