如何从角度2中的回调函数调用父函数?

Kri*_*rki 1 typescript ionic2 angular2-components ionic3 angular

这是一堂课

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);
}

}
Run Code Online (Sandbox Code Playgroud)

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

提前致谢.

Osc*_*Paz 5

使用箭头函数,它捕获以下值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);
   }
}
Run Code Online (Sandbox Code Playgroud)