Ionic 4,使用加载器时出错
loading.present 不是函数
这是我的代码:
const loading = this.loadingController.create({
message: 'Loading',
});
loading.present();
最佳答案
这是因为 loadingController.create() 是一个异步方法,在你在变量 loading
中获取 HTMLIonLoadingElement 的实例之前,
您正在调用目前未定义的 loading/present()
。
所以你需要等到在调用 loadingController.create()
如何解决:简单使用 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/