[英]How to close modal popup window on click of submit button in angular (without using data-dismiss modal of bootstrap code)?
如果您使用ng-bootstrap創建模態,則可以在構造函數中聲明modalservice,然后close函數將起作用。
constructor(private modalService: NgbActiveModal){}
public onClick(id: number): void{
this.modalService.close();
//Your code goes here
}
如果您遵循模態窗口的不同邏輯。 請張貼一些代碼,以便任何人都能為您提供更好的解決方案。
import { Component, TemplateRef } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
@Component({
selector: 'demo-modal-service-static',
template: `<button type="button" class="btn btn-primary" (click)="openModal(template)">Create template modal</button>
<ng-template #template>
<div class="modal-header">
<h4 class="modal-title pull-left">Modal</h4>
<button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
This is a modal.
</div>
</ng-template>`
})
export class DemoModalServiceStaticComponent {
modalRef: BsModalRef;
constructor(private modalService: BsModalService) {}
openModal(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template);
}
}
使用hide()
方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.