Angular 2 - How do I pass a parameter to a routerLink that is binded property?

839 views Asked by At

I'm having a bit of trouble finding some documentation as to how I can pass a binded property as a parameter in my routerLink.

<a [routerLink]="['/dashboards', {{ product.id }} ]'" class="dead-link">
    <div class="card-header">
        {{ product.programName }}
    </div>
    <div class="card-block">
        <h4 class="card-title product-name">{{ product.name }}</h4>
        <p class="card-text product-description">{{ product.description | TruncatePipe }}</p>
    </div>
    <div class="card-footer text-muted">
        Last Updated {{ product.modifiedDate | date: 'MMMM d, y' }}
    </div>
</a>

Is there a way to do this? I'm currently getting the following error:

EXCEPTION: Error: Uncaught (in promise): Template parse errors:
Lexer Error: Unterminated quote at column 31 in expression [['/dashboards', {product.id} ]'] ("<a [ERROR ->][routerLink]="['/dashboards', {product.id} ]'" class="dead-link">
    <div class="card-header">

Thank you all!

1

There are 1 answers

0
YairTawil On BEST ANSWER
<a [routerLink]="['/dashboards', {{ product.id }} ]'" class="dead-link">

you have extra ', and you don't need the "{{}}" around product.id

<a [routerLink]="['/dashboards', product.id ]'" class="dead-link">

Good Luck!