Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 2 passing params in route

I have a component from where i need to pass data to another component on click of button so I have used [routerLink] property in anchor like this

<a [routerLink]="['/employeedetail' , name, address, 
detail3 , detail4, detail5, detail6 , detail7, detail8 , 
detail9, detail10></a>

defined corresponding route in app.route.ts

    {
    path: 'employeedetail/:name/:address/:detail3 /:detail4
    /:detail5 /:detail6/:detail7 /:detail8 /:detail9 /:detail10 ',
    component : employeedetailComponent
    }

In perfect world it should work but it does not as it given an error saying

zone.js:355Unhandled Promise rejection: Unsupported number of argument for pure functions: 11 ; Zone: ; Task: Promise.then ; Value: Error: Unsupported number of argument for pure functions: 11(…) Error: Unsupported number of argument for pure functions: 11

I researched about this and found that angular2 router fails when there are 10 elements in inline template ,I tried out by removing last param in URL (detail10) and no error .

Question is how to pass these large number of params in url using [routerlink] or should I be using different approach for passing data from one component to another component ?

like image 710
Dmehro Avatar asked Feb 20 '26 11:02

Dmehro


1 Answers

You can use queryParams to pass params in the url.

<a [routerLink]="['/employeedetail' , name, address]" [queryParams]="{detail3: detail3, detail4: detail4}">Somewhere</a>

Using query params are better for optional params, it makes your url more readable.

like image 152
Alex Kojin Avatar answered Feb 23 '26 01:02

Alex Kojin