Base solution for your next web application
Open Closed

How to unsubscribe from an event using abp.event.off? #11086


User avatar
0
bluescopesteel created

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version?11.0
  • What is your product type (Angular or MVC)?Angular
  • What is product framework type (.net framework or .net core)?.net core

I have a parent component A that has a child component B. From component B, I am trying to open a modal. The event is registered in component A

In component B, when I am clicking on the button to open the modal, I am calling the following function

showPartsModal(): void { abp.event.trigger('showPartsModal', this.models, this.selectedModels, this.orderId); }

In component A, I have ` ngOnInit() { this.registerToEvents(); }

registerToEvents() { abp.event.on('showPartsModal', (models, selectedModels, orderId) => { this.batchPartsModal.show(selectedModels, selectedModels, orderId); });`

But this event is getting called multiple times when I come back to the page and click on the button after visiting other pages. I found similar issues faced by others in which they suggest we have to unsubscribe to the event so that it does not get called multiple times. But I could not find any example for this.I saw this particular link, https://github.com/aspnetzero/aspnet-zero-core/issues/3929 But still not very sure , how I can implement it for my scenario. Could you please help me out?


1 Answer(s)