Ngx-bootstrap: Modal service: how to handle Esc and backdrop click?

Created on 22 Jul 2017  路  1Comment  路  Source: valor-software/ngx-bootstrap

Good work on the new BsModalService guys! Very happy with it. Using a ComponentLoader is a good move.

One thing I am missing, which is available for the ModalDirective but not in the service, are the show/shown/hide/hidden events and especially the dismiss reasons of the hidden event. For the show/shown events you can use an approach like implementing the constructor or ngOnInit of the loaded component. Unfortunately the ngOnDestroy of the component doesn't seem to fire. Therefore there seems to be no way to handle the Esc or a backdrop click.

Is it possible to expose at least an event for the modal hide to the BsModalRef?
Let me know if I can be of any help.

comp(modal) easy (hours)

Most helpful comment

By the looks of it, you are exposing these events at the level of the modal service. That's fairly global. Since the modal service can have multiple modals open, you cannot distinguish for which modal the event was for.
It might make more sense to expose the events to the BsModalRef so you can subscribe per modal.
Or am I missing where these events are meant for?
Fortunately you have fixed the ngOnDestroy lifetime hook as well. In my use case it's probably enough to use that to take care of modal cancel actions.
Thanks again for your work.

>All comments

By the looks of it, you are exposing these events at the level of the modal service. That's fairly global. Since the modal service can have multiple modals open, you cannot distinguish for which modal the event was for.
It might make more sense to expose the events to the BsModalRef so you can subscribe per modal.
Or am I missing where these events are meant for?
Fortunately you have fixed the ngOnDestroy lifetime hook as well. In my use case it's probably enough to use that to take care of modal cancel actions.
Thanks again for your work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phmello picture phmello  路  3Comments

MrBlaise picture MrBlaise  路  3Comments

juanitavollmering picture juanitavollmering  路  3Comments

pgeyman picture pgeyman  路  3Comments

tuoitrexuquang picture tuoitrexuquang  路  3Comments