-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
selector.service.ts
32 lines (26 loc) · 948 Bytes
/
selector.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Injectable } from '@angular/core'
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
import { SelectorModalComponent } from '../components/selectorModal.component'
import { SelectorOption } from '../api/selector'
@Injectable({ providedIn: 'root' })
export class SelectorService {
private current: NgbModalRef|null = null
get active (): boolean {
return !!this.current
}
/** @hidden */
private constructor (
private ngbModal: NgbModal,
) { }
show <T> (name: string, options: SelectorOption<T>[]): Promise<T> {
const modal = this.ngbModal.open(SelectorModalComponent)
this.current = modal
modal.result.finally(() => {
this.current = null
})
const instance: SelectorModalComponent<T> = modal.componentInstance
instance.name = name
instance.options = options
return modal.result as Promise<T>
}
}