M
M
malayamarisha2022-03-23 07:04:57
Angular
malayamarisha, 2022-03-23 07:04:57

How to solve undefined' is not assignable to type 'CdkTableDataSourceInput' error and why did it occur?

Good day!
Angular Material has been implemented in the project.
In the component template, I am trying to display the table in tasks (the table markup is taken from https://material.angular.io/components/table/overview ).
In the component I do: dataSource?: MatTableDataSource An
error occurs: Type 'MatTableDataSource | undefined' is not assignable to type 'CdkTableDataSourceInput'

<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">


Tell me what I'm doing wrong? In what direction to move?

Attempts:
dataSource: MatTableDataSource<Task> = new MatTableDataSource([])

public dataSource?: MatTableDataSource<Task> = new MatTableDataSource<Task>([]);


There is no error on stackblitz - https://angular-ivy-mlo5qg.stackblitz.io

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eRKa, 2022-03-23
@malayamarisha

Everything is written in the error: the type of MatTableDataSource does not match the type of CdkTableDataSourceInput. Apparently you are trying to pass a field of the MatTableDataSource type to the component, this is your dataSource, and it expects a parameter of the CdkTableDataSourceInput type.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question