Router Link with variables

Asked

Viewed 175 times

-1

again I have brought a doubt about Angular!!

I am angular developer 1,5 years and to date I have not found a way to use Routerlink passing the URL through a variable.

The ways I tried were all these:

<a [routerLink]="{{item.url}}">{{item.label}}</a>
<a [routerLink]="[{{item.url}}]">{{item.label}}</a>
<a [routerLink]="[/{{item.url}}]">{{item.label}}</a>
<a [routerLink]="getUrl()">{{item.label}}</a>

But all of these did not work... rs

Could someone tell me if there’s a way to accomplish this?

Thank you in advance

2 answers

0

I learned it personally....

First and most important, you must import the angular module: 'Routermodule', I know it’s basic, but it’s good to make it 100% clear.

After that you must pass your variable without {{variable}}, as follows:

<a [routerLink]="item.url">{{item.label}}</a>

This variable, must be of type 'string'.

-3

Try this.

<a [routerLink]="['/hero', hero.id]">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.