javascript - 尝试关闭 Ionic Loader 时出错

标签 javascript angularjs ionic-framework ionic3

我有一个 Ionic3 应用程序,它根据操作将数据发布到 API,在等待操作完成时,我使用 Ionic 的 LoadingController 显示加载程序。

import { LoadingController } from 'ionic-angular';

我通过以下方式声明加载程序:

this.loader = this.loadingCtrl.create({
   content: "Please wait..."
});

然后我使用加载器:

doSomething(item) {

    this.loader.present().then(()=>{

      this.item.begin(item).then((result) => {

        this.data = result;
        this.loader.dismiss();

      }, (error) => {
        console.log(error);
        this.loader.dismiss();
      });

    });

  }

我收到错误:

ERROR Error: Uncaught (in promise): inserted view was already destroyed

有人能指出我正确的方向吗?

环境:

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.10.2
    ionic (Ionic CLI) : 3.10.3

global packages:

    Cordova CLI : 7.0.1

local packages:

    @ionic/app-scripts : 2.1.4
    Cordova Platforms  : ios 4.4.0
    Ionic Framework    : ionic-angular 3.6.1

System:

    ios-deploy : 1.9.2
    Node       : v7.7.1
    npm        : 4.1.2
    OS         : macOS Sierra
    Xcode      : Xcode 9.0 Build version 9A235

最佳答案

来自loading controller doc

Note that after the component is dismissed, it will not be usable anymore and another one must be created. This can be avoided by wrapping the creation and presentation of the component in a reusable function as shown in the usage section below.

所以你的错误是因为你有创建和呈现的分割。

import { LoadingController } from 'ionic-angular';

constructor(public loadingCtrl: LoadingController) { }

presentLoadingDefault() {
  const loading = this.loadingCtrl.create({
    content: 'Please wait...'
  });

  loading.present();

  setTimeout(() => {
    loading.dismiss();
  }, 5000);
}

关于javascript - 尝试关闭 Ionic Loader 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46830934/

相关文章:

javascript - 将可观察数组值累积到单个最终数组中

javascript - 在 JavaScript 中从 JSON 对象访问动态值

javascript - 由于某种原因, document.getElementById().innerHTML 不起作用?

javascript - 动态添加项目到ng-repeat数组javascript

javascript - Node : convert string to buffer

javascript - 如何使用 Angular 在菜单单击时在 div 中加载 html?

angular - Nx工作区+本地存储

node.js - "sudo npm install -g ionic"什么都不显示

javascript - 类型错误 : Cannot read property 'controller' of undefined

javascript - 如何重新调整我的指令以在两个不同的范围内工作?