@@ -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 , Observer , Subject , merge } from 'rxjs' ;
@@ -170,15 +171,17 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
170
171
private _viewportRuler : ViewportRuler ,
171
172
private _dragDropRegistry : DragDropRegistry < DragRef , DropListRef > ,
172
173
@Inject ( CDK_DRAG_CONFIG ) private _config : DragRefConfig ,
173
- @Optional ( ) private _dir : Directionality ) {
174
+ @Optional ( ) private _dir : Directionality ,
175
+ // @breaking -change 8.0.0 _changeDetectorRef parameter to be made required.
176
+ private _changeDetectorRef ?: ChangeDetectorRef ) {
174
177
175
178
const ref = this . _dragRef = new DragRef ( element , this . _document , this . _ngZone ,
176
179
this . _viewContainerRef , this . _viewportRuler , this . _dragDropRegistry ,
177
180
this . _config , this . dropContainer ? this . dropContainer . _dropListRef : undefined ,
178
181
this . _dir ) ;
179
182
ref . data = this ;
180
183
this . _syncInputs ( ref ) ;
181
- this . _proxyEvents ( ref ) ;
184
+ this . _handleEvents ( ref ) ;
182
185
}
183
186
184
187
/**
@@ -286,13 +289,17 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
286
289
} ) ;
287
290
}
288
291
289
- /**
290
- * Proxies the events from a DragRef to events that
291
- * match the interfaces of the CdkDrag outputs.
292
- */
293
- private _proxyEvents ( ref : DragRef < CdkDrag < T > > ) {
292
+ /** Handles the events from the underlying `DragRef`. */
293
+ private _handleEvents ( ref : DragRef < CdkDrag < T > > ) {
294
294
ref . started . subscribe ( ( ) => {
295
295
this . started . emit ( { source : this } ) ;
296
+
297
+ // Since all of these events run outside of change detection,
298
+ // we need to ensure that everything is marked correctly.
299
+ if ( this . _changeDetectorRef ) {
300
+ // @breaking -change 8.0.0 Remove null check for _changeDetectorRef
301
+ this . _changeDetectorRef . markForCheck ( ) ;
302
+ }
296
303
} ) ;
297
304
298
305
ref . released . subscribe ( ( ) => {
@@ -301,6 +308,13 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
301
308
302
309
ref . ended . subscribe ( ( ) => {
303
310
this . ended . emit ( { source : this } ) ;
311
+
312
+ // Since all of these events run outside of change detection,
313
+ // we need to ensure that everything is marked correctly.
314
+ if ( this . _changeDetectorRef ) {
315
+ // @breaking -change 8.0.0 Remove null check for _changeDetectorRef
316
+ this . _changeDetectorRef . markForCheck ( ) ;
317
+ }
304
318
} ) ;
305
319
306
320
ref . entered . subscribe ( event => {
0 commit comments