@@ -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' ;
@@ -174,11 +175,12 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
174
175
@Optional ( ) private _dir : Directionality ,
175
176
176
177
/**
177
- * @deprecated `viewportRuler` and `dragDropRegistry ` parameters
178
+ * @deprecated `viewportRuler`, `dragDropRegistry` and `_changeDetectorRef ` parameters
178
179
* to be removed. Also `dragDrop` parameter to be made required.
179
180
* @breaking -change 8.0.0.
180
181
*/
181
- dragDrop ?: DragDrop ) {
182
+ dragDrop ?: DragDrop ,
183
+ private _changeDetectorRef ?: ChangeDetectorRef ) {
182
184
183
185
184
186
// @breaking -change 8.0.0 Remove null check once the paramter is made required.
@@ -191,7 +193,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
191
193
192
194
this . _dragRef . data = this ;
193
195
this . _syncInputs ( this . _dragRef ) ;
194
- this . _proxyEvents ( this . _dragRef ) ;
196
+ this . _handleEvents ( this . _dragRef ) ;
195
197
}
196
198
197
199
/**
@@ -312,13 +314,17 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
312
314
} ) ;
313
315
}
314
316
315
- /**
316
- * Proxies the events from a DragRef to events that
317
- * match the interfaces of the CdkDrag outputs.
318
- */
319
- private _proxyEvents ( ref : DragRef < CdkDrag < T > > ) {
317
+ /** Handles the events from the underlying `DragRef`. */
318
+ private _handleEvents ( ref : DragRef < CdkDrag < T > > ) {
320
319
ref . started . subscribe ( ( ) => {
321
320
this . started . emit ( { source : this } ) ;
321
+
322
+ // Since all of these events run outside of change detection,
323
+ // we need to ensure that everything is marked correctly.
324
+ if ( this . _changeDetectorRef ) {
325
+ // @breaking -change 8.0.0 Remove null check for _changeDetectorRef
326
+ this . _changeDetectorRef . markForCheck ( ) ;
327
+ }
322
328
} ) ;
323
329
324
330
ref . released . subscribe ( ( ) => {
@@ -327,6 +333,13 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
327
333
328
334
ref . ended . subscribe ( ( ) => {
329
335
this . ended . emit ( { source : this } ) ;
336
+
337
+ // Since all of these events run outside of change detection,
338
+ // we need to ensure that everything is marked correctly.
339
+ if ( this . _changeDetectorRef ) {
340
+ // @breaking -change 8.0.0 Remove null check for _changeDetectorRef
341
+ this . _changeDetectorRef . markForCheck ( ) ;
342
+ }
330
343
} ) ;
331
344
332
345
ref . entered . subscribe ( event => {
0 commit comments