2017-08-08 29 views
2

我使用烤麪包,但如果我有2+烤麪包在同一時間打開不會關閉。離子2烤麪包不關閉頁面

let toast = this.toastCtrl.create({ 
     message: 'İnternet bağlantınızda veya sunucuda sorun olabilir.', 
     duration: 3000, 
     position: 'bottom' 
}); 
toast.present(); 
+1

顯示你的整個的.ts頁面請。我認爲你創造了不定式烤麪包。我在同一時間在2+項目中測試了我的項目,他們實際上被解僱了。 – Duannx

回答

2

保留一份參考文獻,並在提交之前先致電dismiss()。這種解決方案可以防止您一次提交多個Toast

我喜歡使用自己的解決方案是處理服務中的所有Toast交互。並注入該服務中的任何組件/網頁/服務,您需要在

ToastService:

import { Injectable } from '@angular/core'; 
import { ToastController, Toast } from 'ionic-angular'; 

@Injectable() 
export class ToastService{ 
    toast: Toast = null; 

    constructor(private toastCtrl: ToastController){ } 

    presentToast(text:string):void{ 
     let toastData = { 
      message: text, 
      duration: 3000, 
      position: 'top' 
     } 

     this.showToast(toastData); 
    } 

    presentClosableToast(text:string):void{ 
     let toastData = { 
      message: text, 
      showCloseButton: true, 
      closeButtonText: 'X', 
      position: 'top' 
     }; 

     this.showToast(toastData); 
    } 

    private showToast(data:any):void{ 
     this.toast ? this.toast.dismiss() : false; 
     this.toast = this.toastCtrl.create(data); 
     this.toast.present(); 
    } 
}