1 import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
3 import { ModalDirective } from 'ngx-bootstrap/modal'
5 import { ConfirmService } from './confirm.service'
8 selector: 'my-confirm',
9 templateUrl: './confirm.component.html',
10 styleUrls: [ './confirm.component.scss' ]
12 export class ConfirmComponent implements OnInit {
13 @ViewChild('confirmModal') confirmModal: ModalDirective
17 expectedInputValue = ''
22 constructor (private confirmService: ConfirmService) {
27 this.confirmModal.config = {
32 this.confirmService.showConfirm.subscribe(
33 ({ title, message, expectedInputValue, inputLabel }) => {
35 this.message = message
37 this.inputLabel = inputLabel
38 this.expectedInputValue = expectedInputValue
45 @HostListener('keydown.enter')
47 this.confirmService.confirmResponse.next(true)
51 @HostListener('keydown.esc')
53 this.confirmService.confirmResponse.next(false)
57 isConfirmationDisabled () {
58 // No input validation
59 if (!this.inputLabel || !this.expectedInputValue) return false
61 return this.expectedInputValue !== this.inputValue
65 this.confirmModal.show()
69 this.confirmModal.hide()