Angular 2-在(单击)事件中使用管道 [英] Angular 2 - Using pipe in (click) event
本文介绍了Angular 2-在(单击)事件中使用管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题可能很简单,但只是找不到例如(click)之类的事件中使用管道的方法.像这样:
My question is probably simple but just can't find the way to use pipe within an event like (click) for example. Something like this:
<button (click)="quizAnswers(answer?.texte | translate | async)"></button>
我总是会出错.我试图用()
或{}
或[]
包装它...
有一些解决方法,例如将内容放在属性中,然后使用this.attribute
在事件中获取它,但是我敢肯定有一种正确的方法!
I always get an error. I tried to wrap it with ()
or {}
or []
...
There are some workaround like putting the content in an attribute and then get it on the event with this.attribute
but I'm sure there is a proper way !
预先感谢您的帮助
推荐答案
一种解决方法是改为在点击处理程序函数中调用管道:
A workaround would be to call your pipes in the click handler function instead:
function quizAnswers(answer)
{
let translatePipe= new TranslatePipe();
...
return translatePipe.transform(answer?.texte);
}
这篇关于Angular 2-在(单击)事件中使用管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文