Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!