如何在模板(动作)函数中传递异步变量? [英] How to pass async variable in template (action) function?
本文介绍了如何在模板(动作)函数中传递异步变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将异步变量传递给该函数. 像这样:
I need to pass async variable to the function. Something like this:
<div class="team" (click)="addToFavorite((match | async)?.id)">
当然我有一个错误.
解析器错误:动作表达式中不能包含管道.
Parser Error: Cannot have a pipe in an action expression.
也许有一种方法可以在JavaScript中转换异步变量?
Maybe there is a way to transform async variable in JavaScript?
推荐答案
简单变量且没有任何可观察值的另一个选项是将变量的值写入隐藏的输入中:
Another option for simple variables and without any observables is writing value of the variable into hidden input:
<div *ngIf="(match | async)?.id">
<input #myControl [value]="(match | async).id" type="hidden" />
<div class="team" (click)="addToFavorite(myControl.value)">
</div>
这篇关于如何在模板(动作)函数中传递异步变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文