/
modal.ts
46 lines (41 loc) · 1.74 KB
/
modal.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {Injectable, Injector, ComponentFactoryResolver} from '@angular/core';
import {NgbModalOptions, NgbModalConfig} from './modal-config';
import {NgbModalRef} from './modal-ref';
import {NgbModalStack} from './modal-stack';
/**
* A service for opening modal windows.
*
* Creating a modal is straightforward: create a component or a template and pass it as an argument to
* the `.open()` method.
*/
@Injectable({providedIn: 'root'})
export class NgbModal {
constructor(
private _moduleCFR: ComponentFactoryResolver, private _injector: Injector, private _modalStack: NgbModalStack,
private _config: NgbModalConfig) {}
/**
* Opens a new modal window with the specified content and supplied options.
*
* Content can be provided as a `TemplateRef` or a component type. If you pass a component type as content,
* then instances of those components can be injected with an instance of the `NgbActiveModal` class. You can then
* use `NgbActiveModal` methods to close / dismiss modals from "inside" of your component.
*
* Also see the [`NgbModalOptions`](#/components/modal/api#NgbModalOptions) for the list of supported options.
*/
open(content: any, options: NgbModalOptions = {}): NgbModalRef {
const combinedOptions = Object.assign({}, this._config, options);
return this._modalStack.open(this._moduleCFR, this._injector, content, combinedOptions);
}
/**
* Dismisses all currently displayed modal windows with the supplied reason.
*
* @since 3.1.0
*/
dismissAll(reason?: any) { this._modalStack.dismissAll(reason); }
/**
* Indicates if there are currently any open modal windows in the application.
*
* @since 3.3.0
*/
hasOpenModals(): boolean { return this._modalStack.hasOpenModals(); }
}