我有这样的模板
<div class="action" *ngFor="let action of (actions | async)">
<div
class="collapsible action-table-row"
[attr.aria-expanded]="actionCollapse.isActive()"
[class.collapse-table-row]="actionCollapse.isActive()"
(click)="openActionCollapse(actionCollapse)"
>
如果条件满足,我想调用一个函数,类似这样的
<div class="action" *ngFor="let action of (actions | async)">
<div
class="collapsible action-table-row"
[attr.aria-expanded]="actionCollapse.isActive()"
[class.collapse-table-row]="actionCollapse.isActive()"
(click)="openActionCollapse(actionCollapse)"
(action.value=="")="callfunction()" //<---- here
>
我怎样才能做到这一点。
答案 0 :(得分:0)
<div class="action" *ngFor="let action of (actions | async)">
<div
class="collapsible action-table-row"
[attr.aria-expanded]="actionCollapse.isActive()"
[class.collapse-table-row]="actionCollapse.isActive()"
(click)="openActionCollapse(actionCollapse)">
{{ action.value=="something" ? callfunction() : '' }} //<---- here
</div>
推荐方式:
<div class="action" *ngFor="let action of (actions | async)">
<div
class="collapsible action-table-row"
[attr.aria-expanded]="actionCollapse.isActive()"
[class.collapse-table-row]="actionCollapse.isActive()"
(click)="openActionCollapse(actionCollapse)">
{{ action.value=="something" ? someVar : '' }} //<---- here
</div>
constructor(){
this.someVar=this.callfunction();
}
callfunction()
{
return "something";
}