HI Everyone
I was trying to figure out how to make the LoadingControlller work with an HTTP request. I didn’t find a solution to this in the forum or stackoverflow.
Thinking a little bit i find this way to: fire Loading component -> make an HTTP request > hide loading component.
import { HttpClient } from '@angular/common/http';
import { LoadingController } from '@ionic/angular';
import { from } from 'rxjs';
....
ngOnInit() {
from(this.presentLoading())
.subscribe(() => {
this.http.get(url)
.subscribe(
(data) => {
console.log(data);
},
(error) => {
console.log(error);
}
)
.add(() => this.loading.dismiss());
});
}
private async presentLoading(): Promise<any> {
this.loading = await this.loadCtrl.create({
message: 'Please wait ...',
});
return await this.loading.present();
}
}
This is working and it solved my problem but i want to know if my solution is correct and if there is a better way to do it.
Related: (None of the solutions there worked for me)
https://forum.ionicframework.com/t/dismiss-a-loadingcontroller/141148
https://github.com/ionic-team/ionic/issues/15109
Ionic:
ionic (Ionic CLI) : 4.9.0 (/usr/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.0.2
@angular-devkit/build-angular : 0.12.4
@angular-devkit/schematics : 7.2.4
@angular/cli : 7.2.4
@ionic/angular-toolkit : 1.4.0
System:
NodeJS : v11.7.0 (/usr/bin/node)
npm : 6.7.0
OS : Linux 4.4
I really appreciate any comments you can provide.