@@ -695,6 +695,10 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
695695 public renderer : Renderer2 ,
696696 protected platformUtil : PlatformUtil
697697 ) {
698+ this . onTransitionEnd = this . onTransitionEnd . bind ( this ) ;
699+ this . onPointerMove = this . onPointerMove . bind ( this ) ;
700+ this . onPointerUp = this . onPointerUp . bind ( this ) ;
701+ this . onPointerLost = this . onPointerLost . bind ( this ) ;
698702 }
699703
700704 /**
@@ -765,7 +769,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
765769 fromEvent ( this . document . defaultView , 'mouseup' ) . pipe ( takeUntil ( this . _destroy ) )
766770 . subscribe ( ( res ) => this . onPointerUp ( res ) ) ;
767771 }
768- this . element . nativeElement . addEventListener ( 'transitionend' , this . onTransitionEnd . bind ( this ) ) ;
772+ this . element . nativeElement . addEventListener ( 'transitionend' , this . onTransitionEnd ) ;
769773 } ) ;
770774
771775 // Set transition duration to 0s. This also helps with setting `visibility: hidden` to the base to not lag.
@@ -779,13 +783,11 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
779783 this . _destroy . next ( true ) ;
780784 this . _destroy . complete ( ) ;
781785
782- if ( this . ghost && this . ghostElement && this . _removeOnDestroy ) {
783- this . ghostElement . parentNode . removeChild ( this . ghostElement ) ;
784- this . ghostElement = null ;
785-
786- if ( this . _dynamicGhostRef ) {
787- this . _dynamicGhostRef . destroy ( ) ;
788- this . _dynamicGhostRef = null ;
786+ if ( this . ghostElement ) {
787+ if ( this . _removeOnDestroy ) {
788+ this . clearGhost ( ) ;
789+ } else {
790+ this . detachGhost ( ) ;
789791 }
790792 }
791793
@@ -1219,11 +1221,15 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
12191221 } ) ;
12201222 }
12211223
1222- protected clearGhost ( ) {
1224+ protected detachGhost ( ) {
12231225 this . ghostElement . removeEventListener ( 'pointermove' , this . onPointerMove ) ;
12241226 this . ghostElement . removeEventListener ( 'pointerup' , this . onPointerUp ) ;
12251227 this . ghostElement . removeEventListener ( 'lostpointercapture' , this . onPointerLost ) ;
12261228 this . ghostElement . removeEventListener ( 'transitionend' , this . onTransitionEnd ) ;
1229+ }
1230+
1231+ protected clearGhost ( ) {
1232+ this . detachGhost ( ) ;
12271233 this . ghostElement . remove ( ) ;
12281234 this . ghostElement = null ;
12291235
@@ -1309,13 +1315,13 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
13091315 if ( this . _pointerDownId !== null ) {
13101316 this . ghostElement . setPointerCapture ( this . _pointerDownId ) ;
13111317 }
1312- this . ghostElement . addEventListener ( 'pointermove' , this . onPointerMove . bind ( this ) ) ;
1313- this . ghostElement . addEventListener ( 'pointerup' , this . onPointerUp . bind ( this ) ) ;
1314- this . ghostElement . addEventListener ( 'lostpointercapture' , this . onPointerLost . bind ( this ) ) ;
1318+ this . ghostElement . addEventListener ( 'pointermove' , this . onPointerMove ) ;
1319+ this . ghostElement . addEventListener ( 'pointerup' , this . onPointerUp ) ;
1320+ this . ghostElement . addEventListener ( 'lostpointercapture' , this . onPointerLost ) ;
13151321 }
13161322
13171323 // Transition animation when the ghostElement is released and it returns to it's original position.
1318- this . ghostElement . addEventListener ( 'transitionend' , this . onTransitionEnd . bind ( this ) ) ;
1324+ this . ghostElement . addEventListener ( 'transitionend' , this . onTransitionEnd ) ;
13191325
13201326 this . cdr . detectChanges ( ) ;
13211327 }
0 commit comments