0

我正在研究一个网格组件,该组件具有将显示为按钮的操作数组

<td *ngFor="let action of actions">
        <button type='button' (click)='action.handler()'>{{action.title}}</button>
</td>

当我尝试这个时,我收到以下错误

_v.context.$implicit.handler is not a function 
4

1 回答 1

1

哦,我明白了

我不应该将处理程序作为字符串传递,我应该传递函数引用本身

所以调用者应该是这样的

this.actions = [{title: 'Edit', handler: this.editItem}];

代替

this.actions = [{title: 'Edit', handler: 'editItem'}];
于 2018-03-18T04:20:33.430 回答