我试着传递参数'这个'以这种方式实现功能:
modalshow = new Confirmation(false, this.changea(this), this.changer);
和确认类是这样的:
constructor(
public show: boolean,
public actionAccept: Function,
public actionReject: Function
) {}
但我一直收到错误:
类型的论点' void'不能分配给类型的参数 '功能'
所以,我不知道问题是什么,我应该怎么做。
答案 0 :(得分:2)
您传递的第二个参数是this.changea(this)
- 结果是您传递了te changea
函数的返回值,而不是函数本身。
如果要将函数作为参数传递,并保留this
的含义,可以使用:
modalshow = new Confirmation(false, () => this.changea(this), this.changer);
您现在已将代码包装在尚未执行的函数中。