仅使用 X 标记删除模态
Remove the Modal by using X mark only
目标:
您应该只使用 X 标记关闭模态,而不是在模态外部单击。
问题:
当我尝试使用语法代码 [config]="{backdrop: 'static'}"
时不知道如何解决它
信息:
- 我是 angular
的新人
- 使用 VS 代码和 ngx-bootstrap
这里是 Minimal Sample StackBlitz 复制问题。
谢谢!
BsModalService
上的 show
方法将 config
对象作为第二个参数。您可以在此处指定背景选项:
在这里,试一试:
import { Component, TemplateRef } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent{
modalRef: BsModalRef;
config = {
backdrop: true,
ignoreBackdropClick: true
};
constructor(private modalService: BsModalService) {}
person:any={}
openModal(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template, this.config);
}
openModalWithComponent() {
this.modalRef = this.modalService.show(ModalContentComponent);
this.modalRef.content.title = 'Modal with component';
}
}
/* This is a component which we pass in modal*/
@Component({
selector: 'modal-content',
template: `
<div class="modal-header">
<h4 class="modal-title pull-left">{{title}}</h4>
</div>
<div class="modal-body">
<input type="text" placeholder="Last Name">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" >Save Last Name</button>
</div>
`
})
export class ModalContentComponent {
title: string;
constructor(private modalService: BsModalService) {}
}
Here's a Working Sample StackBlitz for your ref.
目标: 您应该只使用 X 标记关闭模态,而不是在模态外部单击。
问题: 当我尝试使用语法代码 [config]="{backdrop: 'static'}"
时不知道如何解决它信息:
- 我是 angular 的新人
- 使用 VS 代码和 ngx-bootstrap
这里是 Minimal Sample StackBlitz 复制问题。
谢谢!
BsModalService
上的 show
方法将 config
对象作为第二个参数。您可以在此处指定背景选项:
在这里,试一试:
import { Component, TemplateRef } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent{
modalRef: BsModalRef;
config = {
backdrop: true,
ignoreBackdropClick: true
};
constructor(private modalService: BsModalService) {}
person:any={}
openModal(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template, this.config);
}
openModalWithComponent() {
this.modalRef = this.modalService.show(ModalContentComponent);
this.modalRef.content.title = 'Modal with component';
}
}
/* This is a component which we pass in modal*/
@Component({
selector: 'modal-content',
template: `
<div class="modal-header">
<h4 class="modal-title pull-left">{{title}}</h4>
</div>
<div class="modal-body">
<input type="text" placeholder="Last Name">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" >Save Last Name</button>
</div>
`
})
export class ModalContentComponent {
title: string;
constructor(private modalService: BsModalService) {}
}
Here's a Working Sample StackBlitz for your ref.