forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodal-component.ts
More file actions
71 lines (57 loc) · 2.11 KB
/
modal-component.ts
File metadata and controls
71 lines (57 loc) · 2.11 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Component, ComponentFactoryResolver, HostListener, Renderer, ViewChild, ViewContainerRef } from '@angular/core';
import { Key } from '../../util/key';
import { NavParams } from '../../navigation/nav-params';
import { pascalCaseToDashCase } from '../../util/util';
import { ViewController } from '../../navigation/view-controller';
/**
* @private
*/
@Component({
selector: 'ion-modal',
template:
'<ion-backdrop disableScroll="false" (click)="_bdClick()"></ion-backdrop>' +
'<div class="modal-wrapper">' +
'<div #viewport nav-viewport></div>' +
'</div>'
})
export class ModalCmp {
@ViewChild('viewport', { read: ViewContainerRef }) _viewport: ViewContainerRef;
/** @private */
_bdDismiss: boolean;
/** @private */
_enabled: boolean;
constructor(public _cfr: ComponentFactoryResolver, public _renderer: Renderer, public _navParams: NavParams, public _viewCtrl: ViewController) {
this._bdDismiss = _navParams.data.opts.enableBackdropDismiss;
}
ngAfterViewInit() {
this._load(this._navParams.data.component);
}
/** @private */
_load(component: any) {
if (component) {
const componentFactory = this._cfr.resolveComponentFactory(component);
// ******** DOM WRITE ****************
const componentRef = this._viewport.createComponent(componentFactory, this._viewport.length, this._viewport.parentInjector, []);
this._viewCtrl._setInstance(componentRef.instance);
this._setCssClass(componentRef, 'ion-page');
this._setCssClass(componentRef, 'show-page');
this._setCssClass(componentRef, pascalCaseToDashCase(component.name));
this._enabled = true;
}
}
/** @private */
_setCssClass(componentRef: any, className: string) {
this._renderer.setElementClass(componentRef.location.nativeElement, className, true);
}
_bdClick() {
if (this._enabled && this._bdDismiss) {
return this._viewCtrl.dismiss(null, 'backdrop');
}
}
@HostListener('body:keyup', ['$event'])
_keyUp(ev: KeyboardEvent) {
if (this._enabled && this._viewCtrl.isLast() && ev.keyCode === Key.ESCAPE) {
this._bdClick();
}
}
}