23

I want to create a link to the route with multiple parameters and bind them in tempalte. Until now, I've been doing this by executing the function on (click) event, but I was wondering if it's possible within RouterLink's binding.

Here is the function I use to bind parameters:

redirect() {
    this._router.navigate( ['/category', { cat: this.category, page: this.page }]);
}

My route looks like:

{
    path: 'category/:cat/:page',
    component: PostComponent
}

Will I be able to do the same inside routerLink directive?

Dawid Zbiński
  • 5,521
  • 8
  • 43
  • 70

2 Answers2

47

Yes, of-course, you could use routerLink to form href tag dynamically for navigation. Values in array where each value will get evaluated against Component context.

[routerLink]="['/category', category, page ]"
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
-5

you can do it like, for example :-

<p *ngFor="let emp of employees; let i = index">
  <li><a [routerLink]="['delete', i]">{{emp.name}}</a>({{emp.status}})</li>
</p>

Hope it helps,

Thanks

Alok Kamboj
  • 1,017
  • 11
  • 12