From ec0de52b683cfdc3ee98e59d37d16bf217279404 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 11 Sep 2018 19:39:42 +0200 Subject: [PATCH] fix(drag-drop): dragging class not being applied on drop container (#12921) Fixes the `cdk-drop-dragging` class not being applied to the drop container after 5d0ec23b1d258504ab786e76f80bd9a1a76cd052. The introduction of the `onStable` call caused the event to be bound outside the `NgZone`. --- src/cdk/drag-drop/drag.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cdk/drag-drop/drag.ts b/src/cdk/drag-drop/drag.ts index 6342a28aa66..44484b5e1a4 100644 --- a/src/cdk/drag-drop/drag.ts +++ b/src/cdk/drag-drop/drag.ts @@ -218,8 +218,12 @@ export class CdkDrag implements AfterViewInit, OnDestroy { // their original DOM position and then they get transferred to the portal. this._ngZone.onStable.asObservable().pipe(take(1)).subscribe(() => { const rootElement = this._rootElement = this._getRootElement(); - rootElement.addEventListener('mousedown', this._startDragging); - rootElement.addEventListener('touchstart', this._startDragging); + + // We need to bring the events back into the `NgZone`, because of the `onStable` call. + this._ngZone.run(() => { + rootElement.addEventListener('mousedown', this._startDragging); + rootElement.addEventListener('touchstart', this._startDragging); + }); }); }