navigation - How to execute callback on page pop in Ionic 3? -


i trying data page after dismissed. since navcontroller.pop not allow specify parameters, trying use callback.

calling page code:

export class homepage {      constructor(         private navctrl: navcontroller,         private articleservice: articleservice) {     }  // called on second page's dismiss onarticlefiltersdismissed(data: articlelistfiltermodel) {      return new promise((resolve, reject) => {         if (!data) {             console.log("no data page articlefilterpage");             return;         }          console.log("dismissed page articlefilterpage data ", data);         console.log("this: ", this);          // "this" not points reference of page          this.filterdata = data;         this.loadarticlebriefdata(data);          resolve();     }); }          // shows second page , provides callback parameter onshowfilter(event: mouseevent) {     const filterpage = this.navctrl.push(articlefilterpage, { filters: this.filterdata, callback: this.onarticlefiltersdismissed });  }  private loadarticlebriefdata(filters: articlelistfiltermodel) {      // load data here } 

the second page (that pushed on homepage) code following:

export class articlefilterpage {      dismiss(filter: articlelistfiltermodel) {          this.callback(filter).then(() => {             this.navctrl.pop();         });     }  } 

when articlefilterpage.dismiss function called, gets correct input, points articlefilterpage reference instead of homepage, receive following error message:

error error: uncaught (in promise): typeerror: _this.loadarticlebriefdata not function typeerror: _this.loadarticlebriefdata not function

question: how can transfer second page's data first page?

note: know using modal more straightforward, second page opens modal , modal on modal not seem work (second modal's dismiss close first one).

my question still stands, although instance of xy problem, since original problem related second modal dismissal dismissing first one.

possible answer question

using events possible solution. second page publishes event like:

this.events.publish('on-article-filter-selected', this.filterdata); 

and first page subscribes event:

constructor(public events: events) {   events.subscribe('on-article-filter-selected', (filterdata) => {      this.reloadstuff(filterdata);   }); } 

however, not fond solution since relies on events "flying" around @ application level:

events publish-subscribe style event system sending , responding application-level events across app

my original problem

the button opening second modal (third page) part of form. default, button behaves submit, mistake not specifying type (button).

clicking button closed first modal , opened second 1 in same time, that's why got impression second modal's dismissal closed both modals.

the convenient solution have 2 modals, since naturally allow send information , forth.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -