【发布时间】:2018-02-05 17:34:43
【问题描述】:
我正在使用 Ionic 3 的警报,但我遇到了警报堆积的问题。 我正在使用网络插件来检查用户是否连接到网络(WiFi/2G/3G 等),其想法是在每次用户离线或上线时触发警报。
this.connectSubscription = this.network.onConnect().subscribe(() => {
console.log('network connected!');
let connectedToInternet = this.alertController.create({
subTitle: 'Connected to Internet',
buttons: ['OK']
});
connectedToInternet.present();
});
this.disconnectSubscription = this.network.onDisconnect().subscribe(() => {
let noInternetAlert = this.alertController.create({
subTitle: 'No Internet Connection. Please enable Wifi or Mobile data to continue.',
buttons: ['OK']
});
noInternetAlert.present();
});
当前行为:如果用户多次断开连接并重新连接,则对于网络中的每个更改实例,都会显示一个警报,并且警报会在视图上叠加,直到用户手动关闭警报.
必需的行为:如果用户多次断开连接并重新连接,则对于网络中的每个更改实例,都应显示警报,而旧警报会自动消失,以便在任何给定时间点,用户不会在视图上看到多个警报实例。
【问题讨论】:
标签: angular cordova typescript ionic2 ionic3