【发布时间】:2019-08-05 06:04:19
【问题描述】:
我正在尝试将事件绑定到动态创建的元素上。我非常成功,但我无法将函数绑定到事件。这是我的代码
.ts 代码
data = ['fn1()', 'fn2()', 'fn3()'];
fn1() { alert(1) }
fn2() { alert(2) }
fn3() { alert(3) }
html代码
table>
<ng-container *ngFor='let d of data'>
<tr (click)=d>
<td>
:) !!!
</td>
</tr>
</ng-container>
但是,当我静态添加函数时,它会被调用,即。
<table>
<ng-container *ngFor='let d of data'>
<tr (click)=fn1()>
<td>
:) !!!
</td>
</tr>
</ng-container>
</table>
这行得通,有人可以帮我吗?
【问题讨论】:
标签: angular angular6 angular-directive dynamic-function