首页 > 解决方案 > 如何在 http 获取请求和响应中使用离子加载?

问题描述

我正在创建 Ionic 4 Angular 应用程序,并且正在使用 http 获取和响应。现在我想在请求和响应时进行离子加载。下面我粘贴这个解决方案链接,它在 ionic 3 中可用,但我想要在 ionic 4 中?

Ionic 3 在 http 请求上显示加载符号

标签: angular7ionic4

解决方案


导入加载控制器

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


推荐阅读