@@ -644,7 +644,9 @@ export class IgxOverlayService implements OnDestroy {
644
644
// to eliminate flickering show the element just before animation start
645
645
info . wrapperElement . style . visibility = 'hidden' ;
646
646
}
647
- this . closed . emit ( { id : info . id , componentRef : info . componentRef , event : info . event } ) ;
647
+ if ( ! info . closeAnimationDetaching ) {
648
+ this . closed . emit ( { id : info . id , componentRef : info . componentRef , event : info . event } ) ;
649
+ }
648
650
delete info . event ;
649
651
}
650
652
@@ -659,15 +661,14 @@ export class IgxOverlayService implements OnDestroy {
659
661
if ( info . componentRef ) {
660
662
this . _appRef . detachView ( info . componentRef . hostView ) ;
661
663
info . componentRef . destroy ( ) ;
664
+ delete info . componentRef ;
662
665
}
663
666
if ( info . hook ) {
664
667
info . hook . parentElement . insertBefore ( info . elementRef . nativeElement , info . hook ) ;
665
668
info . hook . parentElement . removeChild ( info . hook ) ;
666
669
delete info . hook ;
667
670
}
668
- if ( info . wrapperElement ) {
669
- delete info . wrapperElement ;
670
- }
671
+
671
672
const index = this . _overlayInfos . indexOf ( info ) ;
672
673
this . _overlayInfos . splice ( index , 1 ) ;
673
674
@@ -679,6 +680,22 @@ export class IgxOverlayService implements OnDestroy {
679
680
}
680
681
this . removeCloseOnEscapeListener ( ) ;
681
682
}
683
+
684
+ // clean all the resources attached to info
685
+ delete info . elementRef ;
686
+ delete info . settings ;
687
+ delete info . initialSize ;
688
+ info . openAnimationDetaching = true ;
689
+ info . openAnimationPlayer ?. destroy ( ) ;
690
+ delete info . openAnimationPlayer ;
691
+ delete info . openAnimationInnerPlayer ;
692
+ info . closeAnimationDetaching = true ;
693
+ info . closeAnimationPlayer ?. destroy ( ) ;
694
+ delete info . closeAnimationPlayer ;
695
+ delete info . closeAnimationInnerPlayer ;
696
+ delete info . ngZone ;
697
+ delete info . wrapperElement ;
698
+ info = null ;
682
699
}
683
700
684
701
private playOpenAnimation ( info : OverlayInfo ) {
@@ -924,7 +941,9 @@ export class IgxOverlayService implements OnDestroy {
924
941
}
925
942
926
943
private openAnimationDone ( info : OverlayInfo ) {
927
- this . opened . emit ( { id : info . id , componentRef : info . componentRef } ) ;
944
+ if ( ! info . openAnimationDetaching ) {
945
+ this . opened . emit ( { id : info . id , componentRef : info . componentRef } ) ;
946
+ }
928
947
if ( info . openAnimationPlayer ) {
929
948
info . openAnimationPlayer . reset ( ) ;
930
949
// calling reset does not change hasStarted to false. This is why we are doing it here via internal field
@@ -940,7 +959,6 @@ export class IgxOverlayService implements OnDestroy {
940
959
}
941
960
942
961
private closeAnimationDone ( info : OverlayInfo ) {
943
- this . closeDone ( info ) ;
944
962
if ( info . closeAnimationPlayer ) {
945
963
info . closeAnimationPlayer . reset ( ) ;
946
964
// calling reset does not change hasStarted to false. This is why we are doing it here via internal field
@@ -954,16 +972,17 @@ export class IgxOverlayService implements OnDestroy {
954
972
// calling reset does not change hasStarted to false. This is why we are doing it here via internal field
955
973
( info . openAnimationPlayer as any ) . _started = false ;
956
974
}
975
+ this . closeDone ( info ) ;
957
976
}
958
977
959
978
private finishAnimations ( info : OverlayInfo ) {
960
979
// TODO: should we emit here opened or closed events
961
- if ( info . openAnimationPlayer ) {
980
+ if ( info . openAnimationPlayer && info . openAnimationPlayer . hasStarted ( ) ) {
962
981
info . openAnimationPlayer . reset ( ) ;
963
982
// calling reset does not change hasStarted to false. This is why we are doing it here via internal field
964
983
( info . openAnimationPlayer as any ) . _started = false ;
965
984
}
966
- if ( info . closeAnimationPlayer ) {
985
+ if ( info . closeAnimationPlayer && info . closeAnimationPlayer . hasStarted ( ) ) {
967
986
info . closeAnimationPlayer . reset ( ) ;
968
987
// calling reset does not change hasStarted to false. This is why we are doing it here via internal field
969
988
( info . closeAnimationPlayer as any ) . _started = false ;
0 commit comments