I followed this tutorial for pop up modal in angular4:
http://jasonwatmore.com/post/2017/01/24/angular-2-custom-modal-window-dialog-box
If I click outside of the modal, the modal disappears. But I do not want the modal to disappear until user clicks the close icon.
Here is the modal's OnInit
:
ngOnInit(): void {
let modal = this;
// ensure id attribute exists
if (!this.id) {
console.error('modal must have an id');
return;
}
// move element to bottom of page (just before </body>) so it can be displayed above everything else
this.element.appendTo('body');
// close modal on background click
this.element.on('click', function (e: any) {
var target = $(e.target);
if (!target.closest('.modal-body').length) {
modal.close();
}
});
// add self (this modal instance) to the modal service so it's accessible from controllers
this.modalService.add(this);
}
Here is the plunker of what I have actually: https://plnkr.co/edit/gPCTvV?p=preview