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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With