Reputation: 385
How do I close Modal Popup on form submit?
Upvotes: 0
Views: 11200
Reputation: 695
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);
}
}
use hide()
method
Upvotes: 0
Reputation: 842
If you are using ng-bootstrap to create modal, you can declare modalservice in constructor and close function will work.
constructor(private modalService: NgbActiveModal){}
public onClick(id: number): void{
this.modalService.close();
//Your code goes here
}
If you are following different logic for modal window. Please post some of you code so that any one give you better solution.
Upvotes: 2