【发布时间】:2017-11-29 04:34:51
【问题描述】:
我正在使用以下代码检查网络状态,但它仅在互联网像开关一样打开或关闭时才有效,但我想在加载页面时知道互联网的状态。
this.network.onConnect().subscribe(data => {
console.log('Net status', data.type)
if (data.type === 'online') {
this.commonService.hideloader();
console.log('data is online');
const path = 'driver_user/vendor_allocations/bulk_create_update.json';
const params = {'vendor_allocations': [save]};
this._tokenService.post(path, params).map(res => res.json()).subscribe(
res => {
this.commonService.hideloader();
console.log('res: ', res);
this.sqliteService.update('entry', this.save_details, 'id', this.save_details.id).then(s => {
console.log('Entry details saved in database', s);
this.commonService.hideloader();
this.commonService.presentToast('தகவல் சேமிக்கப்பட்டது');
this.navCtrl.setRoot('FarmerlistPage');
});
},
error => {
console.log(error);
this.commonService.hideloader();
}
);
} else if (data.type !== 'online') {
console.log('user seems to be offline');
this.commonService.hideloader();
this.commonService.presentToast('தகவல் சேமிக்கப்பட்டது');
}
}, error => console.error(error));
【问题讨论】:
标签: cordova typescript ionic2 cordova-plugins ionic3