* ng的每一行的调用函数 [英] call function for every row of *ngFor angular2
本文介绍了* ng的每一行的调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须显示一个表并为表的每一行调用一个函数,并且为该行调用一次.
I have to display a table and call a function for every row of table and the function called once for a row.
<tr *ngFor="let item of mf.data" >
<td >
<button (click)="remove(item)" class="btn btn-danger">x</button>
</td>
<td>{{item.name}}</td>
<td>{{item.email}}</td>
<td class="text-right">{{item.age}}</td>
<td>{{item.city | uppercase}}</td>
</tr>
请提出如何实现此功能的建议?
Please suggest how will I implement this functionality??
推荐答案
您可以添加指令
@Directive({ selector: '[invoke]'})
class InvokeDirective {
@Output() invoke:EventEmitter = new EventEmitter();
ngAfterContentInit() {
this.invoke.emit(null);
}
}
以及使用方式
<tr *ngFor="let item of mf.data" (invoke)="myFunction(item)" >
这篇关于* ng的每一行的调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文