当*ngFor
完成时,我想调用我的自定义函数。 (我正在使用 jQuery 数据表作为表。当 tr 元素完成时,我想运行此函数 $('#myTable').dataTables(options);
我的代码:
<tbody>
<tr *ngFor="let company of companies; let last = last;">
<td>{{company.shortTitle}}</td>
<td>{{company.shortAddress}}</td>
<td>{{company.taxOffice}}</td>
<td>{{company.taxNumber}}</td>
<td *ngIf="company.eInvoice"><span class="label label-primary">Evet</span></td>
<td *ngIf="!company.eInvoice"><span class="label label-danger">Hayır</span></td>
<td>
<button class="btn btn-primary btn-xs"> <i class="fa fa-edit"></i></button>
<button class="btn btn-danger btn-xs"> <i class="fa fa-trash"></i></button>
</td>
</tr>
最佳答案
为此使用 ngAfterViewInit 生命周期 Hook 。由于 *ngFor
是同步的,因此当 companies
发生变化时,它会更新 DOM,并且添加的 DOM 节点将在 ngAfterViewInit
生命周期 Hook 中可用。
关于javascript - Angular 4 NgFor 已完成事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45799644/