保留一份參考文獻,並在提交之前先致電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();
}
}
顯示你的整個的.ts頁面請。我認爲你創造了不定式烤麪包。我在同一時間在2+項目中測試了我的項目,他們實際上被解僱了。 – Duannx