flo*_*ack 7 cordova ionic-framework angular
我得到了以下Ionic代码片段,用于在工业应用中显示警报/错误:
showError(message: string) {
let toast = this.toastController.create({
message: message,
position: 'top',
duration: 5000,
cssClass: 'danger',
showCloseButton: true
});
toast.present();
}
Run Code Online (Sandbox Code Playgroud)
应用程序每次检测到连接问题时都会触发错误消息,这也将大致在5秒计时器上.
如果更改此代码的时间,多次调用此方法将导致两个或更多错误消息显示在彼此之上.我可以以某种方式检测到吐司已经显示了吗?此外,5000毫秒定时器不是必需的,我可以在重新建立连接时再次删除错误消息.
谢谢和BR Florian
您可以将Toast对象存储在函数外部的变量中,并在显示下一个toast之前调用dismiss()方法:
import { ToastController, Toast } from 'ionic-angular';
toast: Toast;
showError(message: string) {
try {
this.toast.dismiss();
} catch(e) {}
this.toast = this.toastController.create({
message: message,
position: 'top',
duration: 5000,
cssClass: 'danger',
showCloseButton: true
});
toast.present();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4398 次 |
| 最近记录: |