1

I have tried the below solution :

{{page}}

If I remove the {{page}} in the routerlink it works, otherwise it gives error. But I need of course the page number inside the link so that I may direct to the proper page. How can I achieve that?

Jignesh Mistry
  • 2,221
  • 6
  • 25
  • 50
user1238784
  • 2,250
  • 3
  • 22
  • 41

2 Answers2

1

Try like this:) You can pass routerLink argument like array, where is second param can be variable.

<a style="display:inline-block" *ngFor="let page of pages" [routerLink]="['/searchflights',page]">
           {{page}}
</a>
Dmitry Sobolevsky
  • 1,171
  • 6
  • 12
  • This works, however I have a problem: When the url changes after I click the page link, the component does not get reloaded. I have my code in the component's constructor and that is not triggered, because the component is not reloaded. But If I manually type the link in the browser and press enter, the component is reloaded. – user1238784 Jun 28 '18 at 08:22
  • If you want to reload your component you should move it router outlet, and render it on router like that 'searchflights/:id':) – Dmitry Sobolevsky Jun 28 '18 at 12:00
0

Try making it like this, just by changing the comma positioning:

<a style="display:inline-block" *ngFor="let page of pages" [routerLink]="['/searchflights/'{{page}}]">
    {{page}}
</a>
Prachi
  • 3,478
  • 17
  • 34