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