Skip to content

Commit f63918a

Browse files
committed
fix(cdk/scrolling): error when querying for CdkVirtualScrollViewport as CdkScrollable (#25937)
In an earlier change we started providing the `CdkVirtualScrollable` through the `VIRTUAL_SCROLLABLE` token, but the change wasn't reflected in the `CdkVirtualScrollViewport` which was causing an error. Fixes #25917. (cherry picked from commit fcfb99d)
1 parent 53588b5 commit f63918a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/cdk/scrolling/virtual-scroll-viewport.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ArrayDataSource} from '@angular/cdk/collections';
22
import {
3+
CdkScrollable,
34
CdkVirtualForOf,
45
CdkVirtualScrollViewport,
56
ScrollDispatcher,
@@ -1175,6 +1176,18 @@ describe('CdkVirtualScrollViewport', () => {
11751176
.toBe(50);
11761177
}));
11771178
});
1179+
1180+
it('should be able to query for a virtual scroll viewport as a CdkScrollable', () => {
1181+
TestBed.configureTestingModule({
1182+
imports: [ScrollingModule],
1183+
declarations: [VirtualScrollableQuery],
1184+
}).compileComponents();
1185+
1186+
const fixture = TestBed.createComponent(VirtualScrollableQuery);
1187+
fixture.detectChanges();
1188+
1189+
expect(fixture.componentInstance.scrollable).toBeTruthy();
1190+
});
11781191
});
11791192

11801193
/** Finish initializing the virtual scroll component at the beginning of a test. */
@@ -1565,3 +1578,10 @@ class VirtualScrollWithScrollableWindow {
15651578
.fill(0)
15661579
.map((_, i) => i);
15671580
}
1581+
1582+
@Component({
1583+
template: '<cdk-virtual-scroll-viewport itemSize="50"></cdk-virtual-scroll-viewport>',
1584+
})
1585+
class VirtualScrollableQuery {
1586+
@ViewChild(CdkScrollable) scrollable: CdkScrollable;
1587+
}

src/cdk/scrolling/virtual-scroll-viewport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const SCROLL_SCHEDULER =
7474
virtualScrollable: CdkVirtualScrollable | null,
7575
viewport: CdkVirtualScrollViewport,
7676
) => virtualScrollable || viewport,
77-
deps: [CdkVirtualScrollable, CdkVirtualScrollViewport],
77+
deps: [[new Optional(), new Inject(VIRTUAL_SCROLLABLE)], CdkVirtualScrollViewport],
7878
},
7979
],
8080
})

0 commit comments

Comments
 (0)