How to apply pipe to value in RouterLink?

后端 未结 2 731
说谎
说谎 2021-01-29 03:30

I have the following route in Angular 7:

{{category.name}}


        
相关标签:
2条回答
  • 2021-01-29 04:19

    Try removing the curly brackets like this:

    <a [routerLink]="['/categories', category.name | slugify, category.id]">{{category.name}}</a>

    You don't need them there because you are using property binding which is already evaluating to TypeScript code.

    0 讨论(0)
  • 2021-01-29 04:24

    what about this

    <a [routerLink]="['/categories', slugifyPipe.transform(category.name), category.id]">{{category.name}}</a>
    

    and in your constructor,

    constructor(private slugifyPipe: SlugifyPipe) {
    }
    

    also you need to provide SlugifyPipe in your module providers

    0 讨论(0)
提交回复
热议问题