为Ionic2中的警报设置超时
我已经创建了一条警报消息,我只想在设定的时间后关闭它。下面是我的代码:为Ionic2中的警报设置超时,ionic2,Ionic2,我已经创建了一条警报消息,我只想在设定的时间后关闭它。下面是我的代码: showarter(){ 让alert=this.alertCtrl.create({ 副标题:“您提供的信息不完整或无效。请检查您的条目,然后再次检查。” }); alert.present(); }对于此类问题,您更喜欢使用toast,而不是使用alert,您可以显示任意时间 要使用toast,您可以按如下所述进行操作: import {Toast} from 'ionic-native'; Toast.sh
showarter(){
让alert=this.alertCtrl.create({
副标题:“您提供的信息不完整或无效。请检查您的条目,然后再次检查。”
});
alert.present();
}
对于此类问题,您更喜欢使用toast,而不是使用alert,您可以显示任意时间
要使用toast,您可以按如下所述进行操作:
import {Toast} from 'ionic-native';
Toast.show("The information you have provided is incomplete or invalid. Please check your entries and check again.", '3000', 'center').subscribe(
toast => {
console.log(toast);
}
);
“3000”:是要显示的时间,计时单位为毫秒,因此3000=3秒。
“中间”:是烤面包片的位置,可以是顶部、中间或底部。如果要使用超时来调用警报 您可以像这样使用全局
setTimeout()
函数:
showAlert() {
let alert = this.alertCtrl.create({
subTitle: 'The information you have provided is incomplete or invalid. Please check your entries and check again.'
});
setTimeout(()=>alert.present(),3000);
}
如果您想在超时后退出
setTimeout(()=>alert.dismiss(),3000);
我想为它设置超时,你是说在一段时间后解雇。。?或者在一段时间后创建?Toast和alert完全不同。事实上,祝酒会有一个暂停时间,并不意味着它们适合这个时间case@MorKadosh根据尼希尔所说的情景,似乎他的目的也可以通过吐司来实现。