angular - 如何使用离子加载事件“ionLoadingWillPresent”?
问题描述
那里。我想知道如何在离子加载的 Ionic V4 中使用事件“ionLoadingWillPresent”。
我知道 IonLoading 是一个接口,这里是源代码:
interface IonLoading extends JSXBase.HTMLAttributes<HTMLIonLoadingElement> {
//...
'onIonLoadingWillPresent'?: (event: CustomEvent<void>) => void;
//...
}
这是一个接口。
这是我的代码:
constructor(
public loadingController: LoadingController,
public ionLoading: HTMLIonLoadingElement
) {}
async triggerLoading() {
const loading = await this.loadingController.create({
message: '',
duration: 2000,
backdropDismiss: false,
showBackdrop: false,
spinner: 'dots',
translucent: false,
});
// Here is my try, I use getTop methods to get the Ion-Loading Elements.
this.ionLoading = await this.loadingController.getTop();
this.ionLoading.onIonLoadingWillPresent = ()=> {
console.log('hello')
};
// events
await loading.present();
await loading.onDidDismiss();
console.log('loading is didmissed!');
}
- 更新:
this.loadingController.getTop().then(res => {
res.addEventListener('ionLoadingWillPresent', (event: any) => {
// no console from this code
console.log(event);
});
});
--
onIonLoadingWillPresent
但是,小弟,ionLoading没有属性,这个事件怎么用呢?
此类事件如:
ionLoadingDidDismiss
, ionLoadingDidPresent
, ionLoadingWillDismiss
, ionLoadingWillPresent
.
在页面上:离子加载 Api
我想知道如何使用这些事件。非常感谢。
PS:不是组件已经拥有的onDidDismiss
方法。onWillDismiss
ion-loading-controller
解决方案
我认为您可以像这样订阅事件:
this.ionLoading.addEventListener('ionLoadingWillPresent', (event: any) => {
});
如果这不能解决问题,那么我不确定您获得 ionLoading 参考的方式是否正确,但我需要为此找到一个代码片段。
推荐阅读
- telegram - 禁用除管理员外的电报组通知
- mysql - Laravel Mysql 语句类似 fcm 主题条件
- python - Django中匹配url的正则表达式
- python - 使用 Flask 运行服务器会带来不同的项目
- haskell - 您如何不否定列表中的数字?
- typescript - 界面深度选择
- typescript - Typescript Generics:子实例的返回类型
- groovy - 如何使用 Groovy 使用 post() 方法在标头上发布 API 密钥?
- discord.js - 如何获取某个类别下的频道 ID?
- php - Laravel 控制器功能超时,50000 个用户