1 import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
3 import { ModalDirective } from 'ngx-bootstrap/modal'
5 import { ConfirmService } from './confirm.service'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
9 selector: 'my-confirm',
10 templateUrl: './confirm.component.html',
11 styleUrls: [ './confirm.component.scss' ]
13 export class ConfirmComponent implements OnInit {
14 @ViewChild('confirmModal') confirmModal: ModalDirective
18 expectedInputValue = ''
22 confirmButtonText = ''
25 private confirmService: ConfirmService,
32 this.confirmModal.config = {
37 this.confirmService.showConfirm.subscribe(
38 ({ title, message, expectedInputValue, inputLabel, confirmButtonText }) => {
40 this.message = message
42 this.inputLabel = inputLabel
43 this.expectedInputValue = expectedInputValue
45 this.confirmButtonText = confirmButtonText || this.i18n('Confirm')
52 @HostListener('keydown.enter')
54 this.confirmService.confirmResponse.next(true)
58 @HostListener('keydown.esc')
60 this.confirmService.confirmResponse.next(false)
64 isConfirmationDisabled () {
65 // No input validation
66 if (!this.inputLabel || !this.expectedInputValue) return false
68 return this.expectedInputValue !== this.inputValue
73 this.confirmModal.show()
77 this.confirmModal.hide()