8
8
9
9
import { Directionality } from '@angular/cdk/bidi' ;
10
10
import { ListRange } from '@angular/cdk/collections' ;
11
- import { Platform } from '@angular/cdk/platform' ;
12
11
import {
13
- afterNextRender ,
14
12
booleanAttribute ,
15
13
ChangeDetectionStrategy ,
16
14
ChangeDetectorRef ,
17
15
Component ,
18
16
ElementRef ,
19
17
inject ,
20
18
Inject ,
21
- Injector ,
22
19
Input ,
23
20
NgZone ,
24
21
OnDestroy ,
@@ -28,20 +25,21 @@ import {
28
25
ViewChild ,
29
26
ViewEncapsulation ,
30
27
} from '@angular/core' ;
28
+ import { Platform } from '@angular/cdk/platform' ;
31
29
import {
32
30
animationFrameScheduler ,
33
31
asapScheduler ,
34
32
Observable ,
35
- Observer ,
36
33
Subject ,
34
+ Observer ,
37
35
Subscription ,
38
36
} from 'rxjs' ;
39
37
import { auditTime , startWith , takeUntil } from 'rxjs/operators' ;
40
38
import { ScrollDispatcher } from './scroll-dispatcher' ;
41
39
import { CdkScrollable , ExtendedScrollToOptions } from './scrollable' ;
40
+ import { VIRTUAL_SCROLL_STRATEGY , VirtualScrollStrategy } from './virtual-scroll-strategy' ;
42
41
import { ViewportRuler } from './viewport-ruler' ;
43
42
import { CdkVirtualScrollRepeater } from './virtual-scroll-repeater' ;
44
- import { VIRTUAL_SCROLL_STRATEGY , VirtualScrollStrategy } from './virtual-scroll-strategy' ;
45
43
import { CdkVirtualScrollable , VIRTUAL_SCROLLABLE } from './virtual-scrollable' ;
46
44
47
45
/** Checks if the given ranges are equal. */
@@ -175,10 +173,6 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
175
173
/** Subscription to changes in the viewport size. */
176
174
private _viewportChanges = Subscription . EMPTY ;
177
175
178
- private _injector = inject ( Injector ) ;
179
-
180
- private _isDestroyed = false ;
181
-
182
176
constructor (
183
177
public override elementRef : ElementRef < HTMLElement > ,
184
178
private _changeDetectorRef : ChangeDetectorRef ,
@@ -256,8 +250,6 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
256
250
this . _detachedSubject . complete ( ) ;
257
251
this . _viewportChanges . unsubscribe ( ) ;
258
252
259
- this . _isDestroyed = true ;
260
-
261
253
super . ngOnDestroy ( ) ;
262
254
}
263
255
@@ -506,29 +498,23 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
506
498
507
499
/** Run change detection. */
508
500
private _doChangeDetection ( ) {
509
- if ( this . _isDestroyed ) {
510
- return ;
501
+ this . _isChangeDetectionPending = false ;
502
+
503
+ // Apply the content transform. The transform can't be set via an Angular binding because
504
+ // bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of
505
+ // string literals, a variable that can only be 'X' or 'Y', and user input that is run through
506
+ // the `Number` function first to coerce it to a numeric value.
507
+ this . _contentWrapper . nativeElement . style . transform = this . _renderedContentTransform ;
508
+ // Apply changes to Angular bindings. Note: We must call `markForCheck` to run change detection
509
+ // from the root, since the repeated items are content projected in. Calling `detectChanges`
510
+ // instead does not properly check the projected content.
511
+ this . ngZone . run ( ( ) => this . _changeDetectorRef . markForCheck ( ) ) ;
512
+
513
+ const runAfterChangeDetection = this . _runAfterChangeDetection ;
514
+ this . _runAfterChangeDetection = [ ] ;
515
+ for ( const fn of runAfterChangeDetection ) {
516
+ fn ( ) ;
511
517
}
512
-
513
- this . ngZone . run ( ( ) => {
514
- this . _changeDetectorRef . markForCheck ( ) ;
515
- afterNextRender (
516
- ( ) => {
517
- this . _isChangeDetectionPending = false ;
518
- // Apply the content transform. The transform can't be set via an Angular binding because
519
- // bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of
520
- // string literals, a variable that can only be 'X' or 'Y', and user input that is run through
521
- // the `Number` function first to coerce it to a numeric value.
522
- this . _contentWrapper . nativeElement . style . transform = this . _renderedContentTransform ;
523
- const runAfterChangeDetection = this . _runAfterChangeDetection ;
524
- this . _runAfterChangeDetection = [ ] ;
525
- for ( const fn of runAfterChangeDetection ) {
526
- fn ( ) ;
527
- }
528
- } ,
529
- { injector : this . _injector } ,
530
- ) ;
531
- } ) ;
532
518
}
533
519
534
520
/** Calculates the `style.width` and `style.height` for the spacer element. */
0 commit comments