如何在 http get 请求和响应中使用 ion-loading?

How to use ion-loading in http get request and response?

我正在创建 Ionic 4 angular 应用程序,我正在使用 http get 和响应。 现在我想在请求时进行离子加载,response.below 我粘贴了这个解决方案 link,它在 ionic 3 中可用,但我想要在 ionic 4 中?

为什么不使用 spinner dialog

导入加载控制器

import { LoadingController } from '@ionic/angular';

构造函数中创建一个对象

constructor(
    private loadingController: LoadingController
) {}

尝试如下。

async presentLoading() {
    const loading = await this.loadingController.create({
      message: 'Please wait...',
      translucent: true,
    });
    return await loading.present();
  }

homeData() {
    this.presentLoading();
    this.dataService.getData().subscribe(response => {
        console.log(response);
        this.loadingController.dismiss();
    });
}

查看官方文档ion-loading