gpt4 book ai didi

javascript - 尝试关闭 Ionic Loader 时出错

转载 作者:行者123 更新时间:2023-12-03 03:14:26 28 4
gpt4 key购买 nike

我有一个 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com