others - Ionic框架 - 无法在ion-button单击事件上使用debounceTime

72 3

当前我有一个带有click事件的ion-button按钮,它调用一个方法。

<ion-button expand="full" color="primary" (click)="sendMsg()">Tap</ion-button>

sendMsg方法包含将对象推入数组并在某些情况下打开模式的语句。

sendMsg = () =>{ // statements to push an objects to an array(this is an array displays on chat page); this.openModal(); }

async openModal() { const myModal = await this.modalController.create({ component: ModalPage, componentProps: { firstAction: this.firstAction, secondAction: this.secondAction, thirdAction: this.thirdAction }, cssClass: 'modal-css', backdropDismiss: false }); 这是一个聊天页面,我们在点击按钮时收到消息,点击显示ion modal,

为了避免这种情况,我想到了添加debounceTime,它有一些时间延迟,并考虑了最新的click事件,这在正常的angular中都有效。

我跟踪了https://coryrylan.com/blog/creating-a-custom-debounce-click-directive-in-angular,但是在Ionic下不起作用。

时间: 原作者:

103 2

使用subject作为事件发出源并控制单击率


const openModalAction=new Subject()


sendMsg = () =>{


// statements to push an objects to an array(this is an array displays on chat page);


openModalAction.next()


}



const openModal=defer(()=>from(this.modalController.create({


 component: ModalPage,


 componentProps: {


 firstAction: this.firstAction,


 secondAction: this.secondAction,


 thirdAction: this.thirdAction


 },


 cssClass: 'modal-css',


 backdropDismiss: false


 })))



const openModalAction.pipe(dounceTime(1000),switchMap(_=>openModal)



原作者:
...