Ionic framework 爱奥尼亚2号';不要在第页关闭
我用吐司,但如果我有2个以上的吐司同时打开,吐司不会关闭Ionic framework 爱奥尼亚2号';不要在第页关闭,ionic-framework,ionic2,Ionic Framework,Ionic2,我用吐司,但如果我有2个以上的吐司同时打开,吐司不会关闭 let toast = this.toastCtrl.create({ message: 'İnternet bağlantınızda veya sunucuda sorun olabilir.', duration: 3000, position: 'bottom' }); toast.present(); 保留对您的祝酒词的引用,并在演讲前对其调用dismise()。此解决方案将避免一次演示多个
let toast = this.toastCtrl.create({
message: 'İnternet bağlantınızda veya sunucuda sorun olabilir.',
duration: 3000,
position: 'bottom'
});
toast.present();
保留对您的祝酒词的引用,并在演讲前对其调用
dismise()
。此解决方案将避免一次演示多个Toast
我喜欢自己使用的解决方案是处理服务中的所有Toast
交互。并将该服务注入到您需要的任何组件/页面/服务中
烤面包服务:
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+标签进行了测试,但他们实际上拒绝了。服务不应该用于UI交互。有关替代解决方案,请参阅。