gpt4 book ai didi

angular - 如何从 Angular 2 中的回调函数调用父函数?

转载 作者:搜寻专家 更新时间:2023-10-30 22:05:10 26 4
gpt4 key购买 nike

这是一个类

export class ChatDetailPage {

constructor(){

}

funcA(){
var options = {
onSubmit: function (text) {
//i want to be able to access funcB from here
this.funcB(text)
},
this.nativeKeyboard.showMessenger(options)
}

funcB(text){
alert (text);
}

}

在这种情况下,我如何从 Anular 2 或 Ionic 3 中的 onsubmit 回调函数调用 funcB。

提前致谢。

最佳答案

使用箭头函数,它捕获 this 的值:

export class ChatDetailPage {

constructor(){

}

funcA(){
var options = {
onSubmit: text => {
//i want to be able to access funcB from here
this.funcB(text)
},
};
this.nativeKeyboard.showMessenger(options)
}

funcB(text){
alert (text);
}
}

关于angular - 如何从 Angular 2 中的回调函数调用父函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49380502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com