Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
Access Class Members within a call back function Angular12 and Capacitor V-3

I am using the below code to navigate to parent component on click of "Device Hardware Back Button". I am using Capacitor 3.0 and device backbutton works properly. Actual issue is that i am not able to access Class members in the callback function.

Below is the code

  export class ConfirmBoxComponent extends DialogContentBase implements OnInit{
     constructor(public dialog: DialogRef, public myService : MyService) {
        super(dialog);
       
      }
      ngOnInit(): void {
        this.handleHardwareBackButton();
      }
     
      public onCancelAction(): void {
        console.log("Cancel confirmed", this.dialog)
        myService.closeDialog();// closeDialog not available thru arrow or callback functions
      }
    
  handleHardwareBackButton(){
   App.addListener('backButton',function(){
    this.onCancelAction() //not able to access onCancelMethod within callback
   })
  }

    }

Issue is that i am getting "this.onCancelAction" is not a method. Also i tried below code but no use.

handleHardwareBackButton(){
   App.addListener('backButton',function(){
    this.dialog.close({ actionConfirmed : false }); //here this line doesn't get executed. Also no errors observed
   }.bind(this))
  }

Am i going wrong somewhere? Please guide me on how to access class members in a callback function?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try something like this...

export class ConfirmBoxComponent extends DialogContentBase implements OnInit {
    constructor(public dialog: DialogRef) {
        super(dialog);

    }
    ngOnInit(): void {
        this.handleHardwareBackButton();
    }

    public onCancelAction(): void {
        console.log("Cancel confirmed", this.dialog)
        this.dialog.close({ actionConfirmed: false });
    }

    handleHardwareBackButton() {
        App.addListener('backButton', () => {
            this.onCancelAction() //not able to access onCancelMethod within callback
        })
    }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda