本文介绍了防止多个离子警报堆叠起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测离子2 实例是否已打开为了不提出另一个警报?
How can I detect if ionic 2 alert ui component instance is already open in order not to present another alert ?
推荐答案
我最终为Ionic的Alert控制器编写了一个包装提供程序,如下所示:
I ended up writing a wrapping provider for Ionic's Alert controller like so :
import { Injectable } from '@angular/core';
import { AlertController } from 'ionic-angular';
@Injectable()
export class Alert {
public alertPresented: any;
constructor(public alertCtrl: AlertController) {
this.alertPresented = false
}
present(title, subTitle) {
let vm = this
if(!vm.alertPresented) {
vm.alertPresented = true
vm.alertCtrl.create({
title: title,
subTitle: subTitle,
buttons: [{
text: 'OK',
handler: () => {
vm.alertPresented = false
}
}],
}).present();
}
}
}
其中 alertPresented
flag可防止出现多个实例
where alertPresented
flag prevents more than one instance from being presented
这篇关于防止多个离子警报堆叠起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!