Skip to content

Commit

Permalink
fix(cdk/scrolling): error when querying for CdkVirtualScrollViewport …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
crisbeto committed Nov 8, 2022
1 parent 53588b5 commit f63918a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/cdk/scrolling/virtual-scroll-viewport.spec.ts
@@ -1,5 +1,6 @@
import {ArrayDataSource} from '@angular/cdk/collections';
import {
CdkScrollable,
CdkVirtualForOf,
CdkVirtualScrollViewport,
ScrollDispatcher,
Expand Down Expand Up @@ -1175,6 +1176,18 @@ describe('CdkVirtualScrollViewport', () => {
.toBe(50);
}));
});

it('should be able to query for a virtual scroll viewport as a CdkScrollable', () => {
TestBed.configureTestingModule({
imports: [ScrollingModule],
declarations: [VirtualScrollableQuery],
}).compileComponents();

const fixture = TestBed.createComponent(VirtualScrollableQuery);
fixture.detectChanges();

expect(fixture.componentInstance.scrollable).toBeTruthy();
});
});

/** Finish initializing the virtual scroll component at the beginning of a test. */
Expand Down Expand Up @@ -1565,3 +1578,10 @@ class VirtualScrollWithScrollableWindow {
.fill(0)
.map((_, i) => i);
}

@Component({
template: '<cdk-virtual-scroll-viewport itemSize="50"></cdk-virtual-scroll-viewport>',
})
class VirtualScrollableQuery {
@ViewChild(CdkScrollable) scrollable: CdkScrollable;
}
2 changes: 1 addition & 1 deletion src/cdk/scrolling/virtual-scroll-viewport.ts
Expand Up @@ -74,7 +74,7 @@ const SCROLL_SCHEDULER =
virtualScrollable: CdkVirtualScrollable | null,
viewport: CdkVirtualScrollViewport,
) => virtualScrollable || viewport,
deps: [CdkVirtualScrollable, CdkVirtualScrollViewport],
deps: [[new Optional(), new Inject(VIRTUAL_SCROLLABLE)], CdkVirtualScrollViewport],
},
],
})
Expand Down

0 comments on commit f63918a

Please sign in to comment.