【发布时间】:2020-06-08 01:33:03
【问题描述】:
事件发射器exitEvent 在组件app 中定义。问题是如果通过作为参数传递来调用函数怎么办?
例如
app.component.ts
@Output() readonly exitEvent = new EventEmitter<any>();
...
cancel() {
const self = this;
const action = {
callback: this.exitEvent.emit.bind(self),
callbackParam: true
}
action['callback'](true);
}
在上面的示例中,调用将无法正确完成并填充如下错误:
ERROR TypeError: "observers is undefined"
next RxJS
emit Angular
【问题讨论】:
-
你的用例是什么?
标签: angular dependency-injection callback closures