Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda