所以我打了一个http电话。在http调用加载出现之前,当响应到来(成功或错误)时,加载被取消并显示Toast。吐司应该持续3秒,但事实并非如此,它会显示0.5秒。每页加载只有一次。
如何在HTTP通话期间显示加载以及如何在加载后关闭后显示toast以便它可以工作?
这是HTTP调用
this.presentLoading();
this.http.post(this.mainUrl + '/api/v1/filters', obj, {headers: headers}).subscribe(data => {
this.loader.dismiss();
this.presentToast(data.json().success_message, 3000, "toast-success");
}, err => {
this.loader.dismiss();
this.presentToast(err.json().error_message, 3000, "toast-error");
});
presentToast功能
presentToast(msg, duration, cssClass) {
let toast = this.toastCtrl.create({
message: msg,
duration: duration,
position: 'bottom',
dismissOnPageChange: true,
cssClass: cssClass
});
toast.onDidDismiss(() => {
// Do something
});
toast.present();
}
presentLoading
presentLoading() {
this.loader = this.loadingCtrl.create({
content: 'Please wait...'
});
this.loader.dismiss().then(()=>{
});
this.loader.present();
}
定义装载程序
...
export class Filter {
public loader = this.loadingCtrl.create({
content: "Please wait.."
});
...