@@ -28,6 +28,7 @@ import {
28
28
ViewContainerRef ,
29
29
OnChanges ,
30
30
SimpleChanges ,
31
+ ChangeDetectorRef ,
31
32
} from '@angular/core' ;
32
33
import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
33
34
import { Observable , Subscription , Observer } from 'rxjs' ;
@@ -171,7 +172,9 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
171
172
private _viewportRuler : ViewportRuler ,
172
173
private _dragDropRegistry : DragDropRegistry < DragRef , DropListRef > ,
173
174
@Inject ( CDK_DRAG_CONFIG ) private _config : DragRefConfig ,
174
- @Optional ( ) private _dir : Directionality ) {
175
+ @Optional ( ) private _dir : Directionality ,
176
+ // @breaking -change 8.0.0 _changeDetectorRef parameter to be made required.
177
+ private _changeDetectorRef ?: ChangeDetectorRef ) {
175
178
176
179
const ref = this . _dragRef = new DragRef ( element , this . _document , this . _ngZone ,
177
180
this . _viewContainerRef , this . _viewportRuler , this . _dragDropRegistry ,
@@ -188,7 +191,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
188
191
. withPreviewTemplate ( this . _previewTemplate ) ;
189
192
}
190
193
} ) ;
191
- this . _proxyEvents ( ref ) ;
194
+ this . _handleEvetns ( ref ) ;
192
195
}
193
196
194
197
/**
@@ -261,13 +264,17 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
261
264
return selector ? getClosestMatchingAncestor ( this . element . nativeElement , selector ) : null ;
262
265
}
263
266
264
- /**
265
- * Proxies the events from a DragRef to events that
266
- * match the interfaces of the CdkDrag outputs.
267
- */
268
- private _proxyEvents ( ref : DragRef < CdkDrag < T > > ) {
267
+ /** Handles the events from the underlying `DragRef`. */
268
+ private _handleEvetns ( ref : DragRef < CdkDrag < T > > ) {
269
269
ref . started . subscribe ( ( ) => {
270
270
this . started . emit ( { source : this } ) ;
271
+
272
+ // Since all of these events run outside of change detection,
273
+ // we need to ensure that everything is marked correctly.
274
+ if ( this . _changeDetectorRef ) {
275
+ // @breaking -change 8.0.0 Remove null check for _changeDetectorRef
276
+ this . _changeDetectorRef . markForCheck ( ) ;
277
+ }
271
278
} ) ;
272
279
273
280
ref . released . subscribe ( ( ) => {
@@ -276,6 +283,13 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
276
283
277
284
ref . ended . subscribe ( ( ) => {
278
285
this . ended . emit ( { source : this } ) ;
286
+
287
+ // Since all of these events run outside of change detection,
288
+ // we need to ensure that everything is marked correctly.
289
+ if ( this . _changeDetectorRef ) {
290
+ // @breaking -change 8.0.0 Remove null check for _changeDetectorRef
291
+ this . _changeDetectorRef . markForCheck ( ) ;
292
+ }
279
293
} ) ;
280
294
281
295
ref . entered . subscribe ( event => {
0 commit comments