How to apply pipe to value in RouterLink?

╄→尐↘猪︶ㄣ 提交于 2021-02-05 11:48:23

问题


I have the following route in Angular 7:

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

The problem is with applying the pipe slugify within the routerlink.

How can I apply a pipe to a value inside routerLink?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/56955248/how-to-apply-pipe-to-value-in-routerlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!