1
- import { ComponentFactoryResolver , ComponentRef , Injectable , Injector , NgModuleRef , Type , ViewContainerRef } from '@angular/core' ;
1
+ import { ComponentFactoryResolver , ComponentRef , Injectable , Injector , NgModuleRef , NgZone , Type , ViewContainerRef } from '@angular/core' ;
2
2
import { Frame , View , ViewBase , ProxyViewContainer , ShowModalOptions } from '@nativescript/core' ;
3
3
4
4
import { NSLocationStrategy } from '../router/ns-location-strategy' ;
@@ -32,7 +32,7 @@ export class ModalDialogParams {
32
32
33
33
@Injectable ( )
34
34
export class ModalDialogService {
35
- constructor ( private location : NSLocationStrategy ) { }
35
+ constructor ( private location : NSLocationStrategy , private zone : NgZone ) { }
36
36
37
37
public showModal ( type : Type < any > , options : ModalDialogOptions ) : Promise < any > {
38
38
if ( ! options . viewContainerRef ) {
@@ -98,8 +98,10 @@ export class ModalDialogService {
98
98
if ( componentView ) {
99
99
componentView . closeModal ( ) ;
100
100
this . location . _closeModalNavigation ( ) ;
101
- detachedLoaderRef . instance . detectChanges ( ) ;
102
- detachedLoaderRef . destroy ( ) ;
101
+ this . zone . run ( ( ) => {
102
+ detachedLoaderRef . instance . detectChanges ( ) ;
103
+ detachedLoaderRef . destroy ( ) ;
104
+ } ) ;
103
105
}
104
106
} ) ;
105
107
@@ -111,20 +113,22 @@ export class ModalDialogService {
111
113
} ) ;
112
114
const detachedFactory = options . resolver . resolveComponentFactory ( DetachedLoader ) ;
113
115
detachedLoaderRef = options . containerRef . createComponent ( detachedFactory , 0 , childInjector , null ) ;
114
- detachedLoaderRef . instance . loadComponent ( options . type ) . then ( ( compRef ) => {
115
- const detachedProxy = < ProxyViewContainer > compRef . location . nativeElement ;
116
+ this . zone . run ( ( ) => {
117
+ detachedLoaderRef . instance . loadComponent ( options . type ) . then ( ( compRef ) => {
118
+ const detachedProxy = < ProxyViewContainer > compRef . location . nativeElement ;
116
119
117
- if ( detachedProxy . getChildrenCount ( ) > 1 ) {
118
- throw new Error ( 'Modal content has more than one root view.' ) ;
119
- }
120
- componentView = detachedProxy . getChildAt ( 0 ) ;
120
+ if ( detachedProxy . getChildrenCount ( ) > 1 ) {
121
+ throw new Error ( 'Modal content has more than one root view.' ) ;
122
+ }
123
+ componentView = detachedProxy . getChildAt ( 0 ) ;
121
124
122
- if ( componentView . parent ) {
123
- ( < any > componentView . parent ) . _ngDialogRoot = componentView ;
124
- ( < any > componentView . parent ) . removeChild ( componentView ) ;
125
- }
125
+ if ( componentView . parent ) {
126
+ ( < any > componentView . parent ) . _ngDialogRoot = componentView ;
127
+ ( < any > componentView . parent ) . removeChild ( componentView ) ;
128
+ }
126
129
127
- options . parentView . showModal ( componentView , { ...options , closeCallback } ) ;
130
+ options . parentView . showModal ( componentView , { ...options , closeCallback } ) ;
131
+ } ) ;
128
132
} ) ;
129
133
}
130
134
}
0 commit comments