import { Observable , Subject } from "rxjs" ; import { first } from "rxjs/operators" ; export class ModalRef { onCreated : Observable < HTMLElement > ; onClose : Observable < any > ; onClosed : Observable < any > ; onShow : Observable < void > ; onShown : Observable < void > ; private readonly _onCreated = new Subject < HTMLElement > ( ) ; private readonly _onClose = new Subject < any > ( ) ; private readonly _onClosed = new Subject < any > ( ) ; private readonly _onShow = new Subject < void > ( ) ; private readonly _onShown = new Subject < void > ( ) ; private lastResult : any ; constructor ( ) { this . onCreated = this . _onCreated . asObservable ( ) ; this . onClose = this . _onClose . asObservable ( ) ; this . onClosed = this . _onClosed . asObservable ( ) ; this . onShow = this . _onShow . asObservable ( ) ; this . onShown = this . _onShow . asObservable ( ) ; } show ( ) { this . _onShow . next ( ) ; } shown ( ) { this . _onShown . next ( ) ; } close ( result ? ) { this . lastResult = result ; this . _onClose . next ( result ) ; } closed ( ) { this . _onClosed . next ( this . lastResult ) ; } created ( el ) { this . _onCreated . next ( el ) ; } onClosedPromise ( ) { return this . onClosed . pipe ( first ( ) ) . toPromise ( ) ; } }