我正在使用Ionic 4和Loading Controller。
async presentLoading() {
const loading = await this.loadingCtrl.create({
message: 'wait. . .'
});
return await loading.present();
}
效果很好。但是现在我想以编程方式关闭加载程序。
this.loadingCtrl.dismiss().then(a => console.log('dismissed'));
即使我在控制台上看到“已关闭”(记录正常),加载覆盖仍在继续。知道可能是什么原因吗?
答案 0 :(得分:0)
您不关闭显示的实际装载程序。您必须使用const RouteAbout = (
<Route key={"1"} exact path={"/About/Photo/Public/:Fuu"} component={About} />
);
const RouteNoMatch = (
<Route key={"2"} exact path={"/About/Photo/:Juu"} component={NoMatch} />
);
变量将其关闭,如下所示:
loading
请注意,我已经使用了您为当前加载程序声明的变量loading.dismiss().then(a => console.log('dismissed'));
。
答案 1 :(得分:0)
If you want to dismiss programmatically use this in your service.
export class LoaderService {
private isLoading = false;
constructor(private loadingController: LoadingController) {
}
async presentLoading() {
// issue generated! so we used Boolean value to set loader dismissed call
firstly so we used this logic
this.isLoading = true;
let loading = await this.loadingController.create({
message: 'Please Wait',
spinner: 'bubbles'
}).then((res) => {
res.present();
if (!this.isLoading) {
// res.dismiss().then(()=> console.log('abort presenting'));
this.loadingController.dismiss().then(() =>
console.log('Dismissed'));
}
});
return loading;
}
async hideLoading(){ this.isLoading = false; 返回等待this.loadingController.dismiss()。then(()=> console.log('Dismissed')); } }