@@ -17,7 +17,6 @@ import {
17
17
Directive ,
18
18
ChangeDetectorRef ,
19
19
SkipSelf ,
20
- AfterContentInit ,
21
20
Inject ,
22
21
} from '@angular/core' ;
23
22
import { Directionality } from '@angular/cdk/bidi' ;
@@ -59,10 +58,13 @@ export interface CdkDropListInternal extends CdkDropList {}
59
58
'[class.cdk-drop-list-receiving]' : '_dropListRef.isReceiving()' ,
60
59
}
61
60
} )
62
- export class CdkDropList < T = any > implements AfterContentInit , OnDestroy {
61
+ export class CdkDropList < T = any > implements OnDestroy {
63
62
/** Emits when the list has been destroyed. */
64
63
private _destroyed = new Subject < void > ( ) ;
65
64
65
+ /** Whether the element's scrollable parents have been resolved. */
66
+ private _scrollableParentsResolved : boolean ;
67
+
66
68
/** Keeps track of the drop lists that are currently on the page. */
67
69
private static _dropLists : CdkDropList [ ] = [ ] ;
68
70
@@ -183,16 +185,6 @@ export class CdkDropList<T = any> implements AfterContentInit, OnDestroy {
183
185
}
184
186
}
185
187
186
- ngAfterContentInit ( ) {
187
- // @breaking -change 11.0.0 Remove null check for _scrollDispatcher once it's required.
188
- if ( this . _scrollDispatcher ) {
189
- const scrollableParents = this . _scrollDispatcher
190
- . getAncestorScrollContainers ( this . element )
191
- . map ( scrollable => scrollable . getElementRef ( ) . nativeElement ) ;
192
- this . _dropListRef . withScrollableParents ( scrollableParents ) ;
193
- }
194
- }
195
-
196
188
/** Registers an items with the drop list. */
197
189
addItem ( item : CdkDrag ) : void {
198
190
this . _unsortedItems . add ( item ) ;
@@ -321,6 +313,20 @@ export class CdkDropList<T = any> implements AfterContentInit, OnDestroy {
321
313
} ) ;
322
314
}
323
315
316
+ // Note that we resolve the scrollable parents here so that we delay the resolution
317
+ // as long as possible, ensuring that the element is in its final place in the DOM.
318
+ // @breaking -change 11.0.0 Remove null check for _scrollDispatcher once it's required.
319
+ if ( ! this . _scrollableParentsResolved && this . _scrollDispatcher ) {
320
+ const scrollableParents = this . _scrollDispatcher
321
+ . getAncestorScrollContainers ( this . element )
322
+ . map ( scrollable => scrollable . getElementRef ( ) . nativeElement ) ;
323
+ this . _dropListRef . withScrollableParents ( scrollableParents ) ;
324
+
325
+ // Only do this once since it involves traversing the DOM and the parents
326
+ // shouldn't be able to change without the drop list being destroyed.
327
+ this . _scrollableParentsResolved = true ;
328
+ }
329
+
324
330
ref . disabled = this . disabled ;
325
331
ref . lockAxis = this . lockAxis ;
326
332
ref . sortingDisabled = coerceBooleanProperty ( this . sortingDisabled ) ;
0 commit comments