1 import { Injectable } from '@angular/core'
2 import { Subject } from 'rxjs/Subject'
3 import 'rxjs/add/operator/first'
4 import 'rxjs/add/operator/toPromise'
6 type ConfirmOptions = {
10 expectedInputValue?: string
11 confirmButtonText?: string
15 export class ConfirmService {
16 showConfirm = new Subject<ConfirmOptions>()
17 confirmResponse = new Subject<boolean>()
19 confirm (message: string, title = '', confirmButtonText?: string) {
20 this.showConfirm.next({ title, message, confirmButtonText })
22 return this.confirmResponse.asObservable().first().toPromise()
25 confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) {
26 this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText })
28 return this.confirmResponse.asObservable().first().toPromise()