在 Ionic2 中设置警报超时

Nik*_*hil 3 ionic2

我创建了一条警报消息,我只想在设定的定义时间后关闭该消息。下面是我的代码:

showAlert() {
 let alert = this.alertCtrl.create({ 
 subTitle: 'The information you have provided is incomplete or invalid. Please check your entries and check again.' 
 });
 alert.present();
}
Run Code Online (Sandbox Code Playgroud)

showAlert() 是将在事件后调用的方法。现在,我想为它设置超时,但我找不到任何解决方案。

Sur*_*Rao 6

如果要使用超时来调用警报,

您可以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);

}
Run Code Online (Sandbox Code Playgroud)

如果您想在超时后关闭,

setTimeout(()=>alert.dismiss(),3000);
Run Code Online (Sandbox Code Playgroud)