1 import { Component, OnDestroy, OnInit, TemplateRef } from '@angular/core';
2 import { FormGroup } from '@angular/forms';
4 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
7 selector: 'cd-confirmation-modal',
8 templateUrl: './confirmation-modal.component.html',
9 styleUrls: ['./confirmation-modal.component.scss']
11 export class ConfirmationModalComponent implements OnInit, OnDestroy {
17 // One of them is needed
18 bodyTpl?: TemplateRef<any>;
19 description?: TemplateRef<any>;
29 boundCancel = this.cancel.bind(this);
30 confirmationForm: FormGroup;
31 private canceled = false;
33 constructor(public activeModal: NgbActiveModal) {
34 this.confirmationForm = new FormGroup({});
38 this.bodyContext = this.bodyContext || {};
39 this.bodyContext['$implicit'] = this.bodyData;
41 throw new Error('No submit action defined');
42 } else if (!this.buttonText) {
43 throw new Error('No action name defined');
44 } else if (!this.titleText) {
45 throw new Error('No title defined');
46 } else if (!this.bodyTpl && !this.description) {
47 throw new Error('No description defined');
52 if (this.onCancel && this.canceled) {
59 this.activeModal.close();
62 stopLoadingSpinner() {
63 this.confirmationForm.setErrors({ cdSubmitButton: true });