When I manually close the modal, everything works fine. I just create a prompt and only call the BsModalRef.hide() method when the prompt (sweetalert) is closed.
However, when the modal is closed using the ESC key or click-outside events provided by Bootstrap, I am still able to subscribe to the BsModalService.onHide event. But I'm unsure how to prevent the modal from closing until the prompt has been answered. bsModalRef: BsModalRef;
constructor(injector: Injector,
public bsModalService: BsModalService) {
super(injector);
}
ngOnInit(): void {
this.bsModalRef = this.bsModalService.show(SomeFormComponent,
{
keyboard: true,
backdrop: true
});
this.bsModalService.onHide.subscribe((e) => {
// ISSUE: modal already closed at this point...
swal({
text: 'Do you want to save changes?',
title: 'Prompt',
icon: 'warning'
}).open().then((answer: ModalResult) => {
switch(answer) {
case ModalResult.Save:
// I want to save and then close the modal
break;
case ModalResult.DontSave:
// Close the modal
break;
default:
// Stay on the modal
break;
}
});
});
}
Any help would be greatly appreciated. Thank you!