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' ;
22import { Frame , View , ViewBase , ProxyViewContainer , ShowModalOptions } from '@nativescript/core' ;
33
44import { NSLocationStrategy } from '../router/ns-location-strategy' ;
@@ -32,7 +32,7 @@ export class ModalDialogParams {
3232
3333@Injectable ( )
3434export class ModalDialogService {
35- constructor ( private location : NSLocationStrategy ) { }
35+ constructor ( private location : NSLocationStrategy , private zone : NgZone ) { }
3636
3737 public showModal ( type : Type < any > , options : ModalDialogOptions ) : Promise < any > {
3838 if ( ! options . viewContainerRef ) {
@@ -98,8 +98,10 @@ export class ModalDialogService {
9898 if ( componentView ) {
9999 componentView . closeModal ( ) ;
100100 this . location . _closeModalNavigation ( ) ;
101- detachedLoaderRef . instance . detectChanges ( ) ;
102- detachedLoaderRef . destroy ( ) ;
101+ this . zone . run ( ( ) => {
102+ detachedLoaderRef . instance . detectChanges ( ) ;
103+ detachedLoaderRef . destroy ( ) ;
104+ } ) ;
103105 }
104106 } ) ;
105107
@@ -111,20 +113,22 @@ export class ModalDialogService {
111113 } ) ;
112114 const detachedFactory = options . resolver . resolveComponentFactory ( DetachedLoader ) ;
113115 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 ;
116119
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 ) ;
121124
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+ }
126129
127- options . parentView . showModal ( componentView , { ...options , closeCallback } ) ;
130+ options . parentView . showModal ( componentView , { ...options , closeCallback } ) ;
131+ } ) ;
128132 } ) ;
129133 }
130134}
0 commit comments