通过单击背景或在模态之外停止关闭模态 [英] stop closing the modal by clicking backdrop or outside the modal
问题描述
我在我们的代码中使用了一个angular2 ng-bootstrap 模态.
I have used one angular2 ng-bootstrap modal in our code.
我希望在模态外部单击时模态不会关闭.当前,在外部单击时该模式已关闭.
I want the modal will not close when I click outside the modal. Currently the modal is getting closed while clicking outside.
在angular1中,我通常通过[keyboard] ="false" [backdrop] ='static'"来执行此操作.但这是时候在angular2中不起作用了.
In angular1 I used to do this by [keyboard]="false" [backdrop]="'static'". But this is time it is not working in angular2.
这是我的朋克车
我的Open方法如下:
My Open method is as follows:
open() {
const modalRef = this.modalService.open(NgbdModalContent);
modalRef.componentInstance.name = 'World';
}
推荐答案
根据@anshuVersatile的回答,我知道我们需要使用一些模式选项.
As per the answer of @anshuVersatile, I understand we need to use some modal options.
然后,我创建一个 NgbModalOptions 的对象,并将其作为第二个参数传递我的开放方法就可以了.
Then I create a object of NgbModalOptions and pass it as second parameter of my open method and it works.
代码如下:
let ngbModalOptions: NgbModalOptions = {
backdrop : 'static',
keyboard : false
};
console.log(ngbModalOptions);
const modalRef = this.modalService.open(NgbdModalContent, ngbModalOptions);
这是更新的朋克车.
这篇关于通过单击背景或在模态之外停止关闭模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!