1 import { Component, ElementRef, ViewChild, Input } from '@angular/core'
2 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
5 selector: 'my-custom-modal',
6 templateUrl: './custom-modal.component.html',
7 styleUrls: [ './custom-modal.component.scss' ]
9 export class CustomModalComponent {
10 @ViewChild('modal', { static: true }) modal: ElementRef
12 @Input() title: string
13 @Input() content: string
14 @Input() close?: boolean
15 @Input() cancel?: { value: string, action?: () => void }
16 @Input() confirm?: { value: string, action?: () => void }
18 private modalRef: NgbModalRef
21 private modalService: NgbModal
28 cancel?: { value: string, action?: () => void },
29 confirm?: { value: string, action?: () => void }
31 if (this.modalRef instanceof NgbModalRef && this.modalService.hasOpenModals()) {
32 console.error('Cannot open another custom modal, one is already opened.')
36 const { title, content, close, cancel, confirm } = input
39 this.content = content
42 this.confirm = confirm
44 this.modalRef = this.modalService.open(this.modal, {
55 if (typeof this.cancel.action === 'function') {
70 if (typeof this.confirm.action === 'function') {
78 return typeof this.cancel !== 'undefined'
82 return typeof this.confirm !== 'undefined'