-1

HTML:

 <button [routerLink]="['/Request']">Request</button>

I am getting data in this component as product.name, product.id etc.

/Request is another view and I need to redirect user to that view on button click (Right now I am achieving this via [routerLink]) and to pass the value product.id to that view, as I want to use the value on that view.

Data:

My data is in the form of list, where on each button click, there would be different ID.

I am unable to pass the value to another view, on button click. What's the best approach?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Sarah Mandana
  • 1,474
  • 17
  • 43
  • https://stackoverflow.com/questions/37880876/how-to-pass-query-parameters-with-a-routerlink-in-the-new-router-v-3-alpha-vlad – Wen W Feb 11 '19 at 01:57
  • @WenHaoWu Using query params won't be secure. I know about it already. That's why I asked for best approach – Sarah Mandana Feb 11 '19 at 02:03

1 Answers1

2

You need to pass the value via URL. To this end, first, you need to declare it in your routing file. For example:

{
  path: 'request/:clientId
  component: RequestComponent
}

After that, just add it to your route. You can do:

<button [routerLink]=['/request', client.id]">Request</button>

or

<button routerLink="/request/{{ client.id }}">Request</button>
Nimantha
  • 6,405
  • 6
  • 28
  • 69
André Pacheco
  • 1,780
  • 14
  • 19