You have probably already imported at the class level with:
import { MatSort, MatTableDataSource } from '@angular/material';
This makes the types MatSort and MatTableDataSource available within your .ts class. However, you are also trying to use the related modules as directives in your component's .html file, to do this your app.module.ts needs to be importing them, I do this with a separate NgModule that imports all of the material components I use i.e.
material\material.module.ts
import { NgModule } from '@angular/core';
import {
MatTableModule,
MatSortModule,
} from '@angular/material';
@NgModule({
imports: [
MatTableModule,
MatSortModule,
],
exports: [
MatTableModule,
MatSortModule,
]
})
export class MaterialModule { }
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
import { MaterialModule } from './material/material.module';
import { AppComponent } from './app.component';
import { myComponent } from './my/my.component';
@NgModule({
declarations: [
AppComponent,
MyComponent
],
imports: [
BrowserModule,
MaterialModule,
BrowserAnimationsModule,
HttpClientModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }