Skip to content

Commit 9b03212

Browse files
committed
fix connect function
1 parent 407dff6 commit 9b03212

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/cdk/table/table.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,13 @@ export class CdkTable<T> implements CollectionViewer, OnInit, AfterContentChecke
422422

423423
let dataStream: Observable<T[]> | undefined;
424424

425-
if (this.dataSource instanceof DataSource) {
426-
dataStream = this.dataSource.connect(this);
425+
// Check if the datasource is a DataSource object by observing if it has a connect function.
426+
// Cannot check this.dataSource['connect'] due to potential property renaming, nor can it
427+
// checked as an instanceof DataSource<T> since the table should allow for data sources
428+
// that did not explicitly extend DataSource<T>.
429+
const connectFunction = (this.dataSource as DataSource<T>).connect;
430+
if (connectFunction instanceof Function) {
431+
dataStream = connectFunction(this);
427432
} else if (this.dataSource instanceof Observable) {
428433
dataStream = this.dataSource;
429434
} else if (Array.isArray(this.dataSource)) {
@@ -434,10 +439,12 @@ export class CdkTable<T> implements CollectionViewer, OnInit, AfterContentChecke
434439
throw getTableUnknownDataSourceError();
435440
}
436441

437-
this._renderChangeSubscription = dataStream.pipe(takeUntil(this._onDestroy)).subscribe(data => {
438-
this._data = data;
439-
this.renderRows();
440-
});
442+
this._renderChangeSubscription = dataStream
443+
.pipe(takeUntil(this._onDestroy))
444+
.subscribe(data => {
445+
this._data = data;
446+
this.renderRows();
447+
});
441448
}
442449

443450
/**

0 commit comments

Comments
 (0)