gpt4 book ai didi

ionic-framework - Ionic 4 : loading. 存在不是函数

转载 作者:行者123 更新时间:2023-12-01 09:12:57 27 4
gpt4 key购买 nike

Ionic 4,使用加载器时出错loading.present 不是函数

这是我的代码:

const loading =  this.loadingController.create({
message: 'Loading',
});

loading.present();

最佳答案

这是因为 loadingController.create() 是一个异步方法,在你在变量 loading 中获取 HTMLIonLoadingElement 的实例之前,您正在调用目前未定义的 loading/present()

所以你需要等到在调用 loadingController.create()

的时候得到 HTMLIonLoadingElement 的实例

如何解决:简单使用 aync/await

const loading = await this.loadingController.create({
message: 'Loading',
});
loading.present();

看到我们在 = 运算符之后使用了 await。所以它确保只有在调用 loadingController.create 完成并且变量加载被初始化时才执行下一行。

NOTE: Don't forget to add async keyword to the function inside which you are using the loader code, as we are using await.

关于ionic-framework - Ionic 4 : loading. 存在不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54053245/

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