6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { CollectionViewer , DataSource , Range , StaticArrayDataSource } from '@angular/cdk/collections' ;
9
+ import { ArrayDataSource , CollectionViewer , DataSource , Range } from '@angular/cdk/collections' ;
10
10
import {
11
11
Directive ,
12
12
DoCheck ,
@@ -35,7 +35,7 @@ import {CdkVirtualScrollViewport} from './virtual-scroll-viewport';
35
35
/** The context for an item rendered by `CdkVirtualForOf` */
36
36
export type CdkVirtualForOfContext < T > = {
37
37
$implicit : T ;
38
- cdkVirtualForOf : NgIterable < T > | DataSource < T > ;
38
+ cdkVirtualForOf : DataSource < T > | Observable < T [ ] > | NgIterable < T > ;
39
39
index : number ;
40
40
count : number ;
41
41
first : boolean ;
@@ -61,15 +61,18 @@ export class CdkVirtualForOf<T> implements CollectionViewer, DoCheck, OnDestroy
61
61
62
62
/** The DataSource to display. */
63
63
@Input ( )
64
- get cdkVirtualForOf ( ) : NgIterable < T > | DataSource < T > { return this . _cdkVirtualForOf ; }
65
- set cdkVirtualForOf ( value : NgIterable < T > | DataSource < T > ) {
64
+ get cdkVirtualForOf ( ) : DataSource < T > | Observable < T [ ] > | NgIterable < T > {
65
+ return this . _cdkVirtualForOf ;
66
+ }
67
+ set cdkVirtualForOf ( value : DataSource < T > | Observable < T [ ] > | NgIterable < T > ) {
66
68
this . _cdkVirtualForOf = value ;
67
69
const ds = value instanceof DataSource ? value :
68
- // Slice the value since NgIterable may be array-like rather than an array.
69
- new StaticArrayDataSource < T > ( Array . prototype . slice . call ( value ) ) ;
70
+ // Slice the value if its an NgIterable to ensure we're working with an array.
71
+ new ArrayDataSource < T > (
72
+ value instanceof Observable ? value : Array . prototype . slice . call ( value ) ) ;
70
73
this . _dataSourceChanges . next ( ds ) ;
71
74
}
72
- _cdkVirtualForOf : NgIterable < T > | DataSource < T > ;
75
+ _cdkVirtualForOf : DataSource < T > | Observable < T [ ] > | NgIterable < T > ;
73
76
74
77
/**
75
78
* The `TrackByFunction` to use for tracking changes. The `TrackByFunction` takes the index and
0 commit comments