天天看點

ionic3 帶參數反向傳值

實作帶參數反向傳值,要在push跳轉的頁面添加一個回調函數 push方式跳轉

getData = (data) =>
{
  return new Promise((resolve, reject) => {
    console.log(data);      
this.data.industryTxt= data.name;
    this.data.industryId = data.id;
    resolve();
  });
};

/**
 * 頁面跳轉
 */
selectIndustry(tb:any) {
  this.navCtrl.push(SettingCategoryPage, {
    tb : tb,
    callback: this.getData
  });
}      

SettingCategoryPage:(跳轉到的頁面)

public callback:any;
constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public httpPost: HttpService
) {
  this.callback   = this.navParams.get('callback');
}      
sendData(event: any): void
{
  this.callback(this.data).then(()=>{ this.navCtrl.pop() });
}      

參考:https://www.jianshu.com/p/147f44e0fe80