Skip to content Skip to sidebar Skip to footer

Event Bus Trigger Duplicating

In the edit modal for my company entity, I open the address entity create modal. This allows the user to create an address for the company. On the .done of the address create app s

Solution 1:

From the documentation on Register To Events:

You can use abp.event.off method to unregister from an event. Notice that; same function should be provided in order to unregister. So, for the example above, you should set the callback function to a variable, then use both in on and off methods.

You're passing in a dummy object:

abp.event.off('addressCreated', {
    id: null
});

Do this:

functionaddressCreated(item) {
    console.log('addressCreated event caught for id: ' + item.id);
    //Call company address servicevar _companyAddressService = abp.services.app.companyAddress;
    _companyAddressService.createCompanyAddress({
        CompanyId: $("#CompanyId").val(),
        AddressId: item.id
    }).done(function () {
        abp.event.off('addressCreated', addressCreated); // Turn off this handlerconsole.log('addressCreated event turned off for id: ' + item.id);
        abp.notify.success(app.localize('AddressCreated'));
        abp.ui.clearBusy('.modal-body');
    });
}

abp.event.on('addressCreated', addressCreated);

The addressCreated function is executing not at all sometime[s]

You're only calling .on once per EditCompanyModal, and then .off-ing it.

Move the .off into this.save = ....

Update

Move the .off into this.init = ....

this.init = function (modalManager) {
    _modalManager = modalManager;

    // ...

    _modalManager.onClose(function () {
        abp.event.off('addressCreated', addressCreated); // Turn off this handler
    });
};

Post a Comment for "Event Bus Trigger Duplicating"