【发布时间】:2017-01-05 14:50:16
【问题描述】:
我想检测 ionic2 应用程序中的慢速互联网并处理它。
我已经完成了谷歌和使用 settimeout 的方法,但是在调用 api 时如何使用它?
我将 api 称为:
AppSettings.API_ENDPOINT = is a constant having api url.
this.returned = this.http.post(`${AppSettings.API_ENDPOINT}login`, "email=" + email + "&password=" + password, { headers: headers }).timeout(100).map(res => res.json()).subscribe(data => {
this.conn_error_msg = '';
if (data.status == 200) {
}
else {
}
},
error => {
this.isDisabled = 0;
this.conn_error_msg = 'Internet connection error. Please try again.';
console.log(JSON.stringify(error.json()));
loader.dismiss();
}
);
使用这种方式我的超时工作正常,但我需要显示警报..
在这里我希望在超时时显示警报
已解决:
this.http.get(url)
.timeout(1000) 。地图(...) .subcribe((success) => {...}, (err) => { // 这里处理超时错误。});
希望它对某人有所帮助。
编码愉快。
【问题讨论】:
-
可以使用 rxjs 超时。