I decided to render my links dynamically on my page and previously the links looked like this
<a routerLink="/home" routerLinkActivate="active">Home</a>
Now that I'm binding data to them to populate them dynamically the syntax is now
<a [attr.routerLink]="link.val" *ngFor="let link of linkData">
{{link.link}}
</a>
I realized the /
wouldn't save in the firebase database for obvious reasons when I really thought about it. But now I can't figure out how to get the /
in there.
I've tried
"/link.val"
"/+link.val"
"/++link.val"
"/(link.val)"
"/{link.val}"
"(/)link.val"
"(/)+link.val"
"/[link.val]"
as well as a few others I can't think of at the moment and nothing is working. It's possible to do this right? Without it the link won't work.
For the binding to work you need a valid template expression. In this case you want to concatenate a literal string with a variable one, so you need:
[attr.routerLink]="'/' + link.val"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments