1 import { first } from 'rxjs/operators'
2 import { Injectable } from '@angular/core'
3 import { Subject } from 'rxjs'
5 type ConfirmOptions = {
9 expectedInputValue?: string
10 confirmButtonText?: string
14 export class ConfirmService {
15 showConfirm = new Subject<ConfirmOptions>()
16 confirmResponse = new Subject<boolean>()
18 confirm (message: string, title = '', confirmButtonText?: string) {
19 this.showConfirm.next({ title, message, confirmButtonText })
21 return this.confirmResponse.asObservable().pipe(first()).toPromise()
24 confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) {
25 this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText })
27 return this.confirmResponse.asObservable().pipe(first()).toPromise()