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

283
Views
registerBackButtonAction, Ionic2, para diferentes páginas

Estoy desarrollando una aplicación Ionic2. Estoy confundido con la funcionalidad registerBackButtonAction .

He hecho esto en una página (digamos pageA). y está funcionando como se esperaba.

 this.platform.registerBackButtonAction(() => { console.log("back presed"); this.abortDownloadAndExit(); });

Ahora quiero hacer alguna otra acción en registerBackButtonAction en alguna otra página (sayPageB). Pero Ionic está tomando medidas desde la página A

¿Cómo puedo registrar diferentes acciones en diferentes páginas?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Como puede ver en los documentos de Ionic , registerBackButtonAction devuelve una función:

Una función que, cuando se llama, anulará el registro de su acción de botón Atrás. Entonces puede usar esa función para restaurar el comportamiento predeterminado al salir de la página, así:

 import { Component} from '@angular/core'; @Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { // Property used to store the callback of the event handler to unsubscribe to it when leaving this page public unregisterBackButtonAction: any; constructor(...) { ... } ionViewDidEnter() { this.initializeBackButtonCustomHandler(); } ionViewWillLeave() { // Unregister the custom back button action for this page this.unregisterBackButtonAction && this.unregisterBackButtonAction(); } public initializeBackButtonCustomHandler(): void { this.unregisterBackButtonAction = this.platform.registerBackButtonAction(() => { this.customHandleBackButton(); }, 10); } private customHandleBackButton(): void { // do what you need to do here ... } }

Entonces, como puede ver, la clave es almacenar la devolución de llamada del método registerBackButtonAction y usarlo más tarde al salir de la página (o cuando desee restaurar el comportamiento predeterminado):

 this.unregisterBackButtonAction = this.platform.registerBackButtonAction(() => { this.customHandleBackButton(); }, 10);
about 4 years ago · Santiago Trujillo 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!