【发布时间】:2017-07-13 20:20:21
【问题描述】:
我正在使用 ionic 2 RC1 并使用 sublime 作为文本编辑器。我需要检查网络连接是否连接。所以为此我使用离子原生Network。但我面临Network.onDisconnect() Observable 的问题。我编辑了initializeApp() 方法,在该方法中我检查网络连接并在连接断开时显示警报。我有以下代码写在app.component.ts
showAlert(title, msg) {
let alert = this.alertCtrl.create({
title: title,
subTitle: msg,
buttons: ['OK']
});
alert.present();
}
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
let disconnectSubscription = Network.onDisconnect().subscribe(() => {
this.showAlert("Error", "No internet connection");
});
StatusBar.styleDefault();
});
}
我面临的问题是,如果应用程序与 Internet 断开连接,则会显示两次警报。我在post 中发现了类似的问题,但没有得到答复。在这方面的任何帮助将不胜感激。 提前致谢!
【问题讨论】:
-
你能解决这个问题吗?
-
不,我没有尝试解决它,因为我已被转移到其他基于 Web 的项目。我认为这个问题现在应该在框架的新版本中得到解决。
标签: angular cordova typescript ionic2 ionic3