1
1
import {
2
- ReflectiveInjector , ComponentFactoryResolver , ViewContainerRef , NgModuleRef ,
3
- Type , Injectable , ComponentRef , Directive
2
+ ComponentFactoryResolver ,
3
+ ComponentRef ,
4
+ Directive ,
5
+ Injectable ,
6
+ NgModuleRef ,
7
+ ReflectiveInjector ,
8
+ Type ,
9
+ ViewContainerRef ,
4
10
} from "@angular/core" ;
11
+
5
12
import { Page } from "tns-core-modules/ui/page" ;
6
13
import { View } from "tns-core-modules/ui/core/view" ;
14
+
7
15
import { DetachedLoader } from "../common/detached-loader" ;
8
16
import { PageFactory , PAGE_FACTORY } from "../platform-providers" ;
9
17
@@ -21,44 +29,61 @@ export class ModalDialogParams {
21
29
}
22
30
}
23
31
32
+ interface ShowDialogOptions {
33
+ containerRef : ViewContainerRef ;
34
+ context : any ;
35
+ doneCallback ;
36
+ fullscreen : boolean ;
37
+ pageFactory : PageFactory ;
38
+ parentPage : Page ;
39
+ resolver : ComponentFactoryResolver ;
40
+ type : Type < any > ;
41
+ }
42
+
24
43
@Injectable ( )
25
44
export class ModalDialogService {
26
- public showModal ( type : Type < any > , options : ModalDialogOptions ) : Promise < any > {
27
- if ( ! options . viewContainerRef ) {
45
+ public showModal ( type : Type < any > ,
46
+ { viewContainerRef, moduleRef, context, fullscreen} : ModalDialogOptions
47
+ ) : Promise < any > {
48
+ if ( ! viewContainerRef ) {
28
49
throw new Error (
29
- "No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions." ) ;
50
+ "No viewContainerRef: " +
51
+ "Make sure you pass viewContainerRef in ModalDialogOptions."
52
+ ) ;
30
53
}
31
54
32
- const viewContainerRef = options . viewContainerRef ;
33
55
const parentPage : Page = viewContainerRef . injector . get ( Page ) ;
56
+ const pageFactory : PageFactory = viewContainerRef . injector . get ( PAGE_FACTORY ) ;
57
+
34
58
// resolve from particular module (moduleRef)
35
59
// or from same module as parentPage (viewContainerRef)
36
- const resolver : ComponentFactoryResolver = ( options . moduleRef || viewContainerRef ) . injector . get (
37
- ComponentFactoryResolver ) ;
38
- const pageFactory : PageFactory = viewContainerRef . injector . get ( PAGE_FACTORY ) ;
60
+ const componentContainer = moduleRef || viewContainerRef ;
61
+ const resolver = componentContainer . injector . get ( ComponentFactoryResolver ) ;
39
62
40
- return new Promise ( ( resolve ) => {
41
- setTimeout ( ( ) => ModalDialogService . showDialog (
42
- type ,
43
- options ,
44
- resolve ,
45
- viewContainerRef ,
46
- resolver ,
63
+ return new Promise ( resolve => {
64
+ setTimeout ( ( ) => ModalDialogService . showDialog ( {
65
+ containerRef : viewContainerRef ,
66
+ context ,
67
+ doneCallback : resolve ,
68
+ fullscreen ,
69
+ pageFactory ,
47
70
parentPage,
48
- pageFactory
49
- ) , 10 ) ;
71
+ resolver,
72
+ type,
73
+ } ) , 10 ) ;
50
74
} ) ;
51
75
}
52
76
53
- private static showDialog (
54
- type : Type < any > ,
55
- options : ModalDialogOptions ,
77
+ private static showDialog ( {
78
+ containerRef ,
79
+ context ,
56
80
doneCallback,
57
- containerRef : ViewContainerRef ,
58
- resolver : ComponentFactoryResolver ,
59
- parentPage : Page ,
60
- pageFactory : PageFactory ) : void {
61
-
81
+ fullscreen,
82
+ pageFactory,
83
+ parentPage,
84
+ resolver,
85
+ type,
86
+ } : ShowDialogOptions ) : void {
62
87
const page = pageFactory ( { isModal : true , componentType : type } ) ;
63
88
64
89
let detachedLoaderRef : ComponentRef < DetachedLoader > ;
@@ -69,7 +94,7 @@ export class ModalDialogService {
69
94
detachedLoaderRef . destroy ( ) ;
70
95
} ;
71
96
72
- const modalParams = new ModalDialogParams ( options . context , closeCallback ) ;
97
+ const modalParams = new ModalDialogParams ( context , closeCallback ) ;
73
98
74
99
const providers = ReflectiveInjector . resolve ( [
75
100
{ provide : Page , useValue : page } ,
@@ -88,7 +113,7 @@ export class ModalDialogService {
88
113
}
89
114
90
115
page . content = componentView ;
91
- parentPage . showModal ( page , options . context , closeCallback , options . fullscreen ) ;
116
+ parentPage . showModal ( page , context , closeCallback , fullscreen ) ;
92
117
} ) ;
93
118
}
94
119
}
@@ -99,7 +124,9 @@ export class ModalDialogService {
99
124
} )
100
125
export class ModalDialogHost { // tslint:disable-line:directive-class-suffix
101
126
constructor ( ) {
102
- throw new Error ( "ModalDialogHost is deprecated. Call ModalDialogService.showModal() " +
103
- "by passing ViewContainerRef in the options instead." ) ;
127
+ throw new Error ( "ModalDialogHost is deprecated. " +
128
+ "Call ModalDialogService.showModal() " +
129
+ "by passing ViewContainerRef in the options instead."
130
+ ) ;
104
131
}
105
132
}
0 commit comments