1

I'm trying to implement a score board for my small project. And when I try to use mat table, it causes me "Can't bind to 'dataSource' since it isn't a known property of 'table'." error. My code : score-screen.components.ts

import { Component, OnInit } from '@angular/core';
import { object } from '@angular/fire/database';
@Component({
  selector: 'app-scoreboard-screen',
  templateUrl: './scoreboard-screen.component.html',
  styleUrls: ['./scoreboard-screen.component.scss']
})
export class ScoreboardScreenComponent implements OnInit {

  lessons = [
    {
      id: 1,
      'description': 'Introduction to Angular Material',
      'duration': '4:17', 
      'seqNo': 1,
      courseId: 12
    },
    {
      id: 2,
      'description': 'Introduction to Angular Material',
      'duration': '4:17', 
      'seqNo': 2,
      courseId: 13
    }
  ]

  displayedColumns = ['seqNo',"description","duration"];

  constructor() { 
    
  }

  ngOnInit(): void {
  }
  

}

scoreboard-screen.component.html

<table mat-table class="lessons-table table-hover" [dataSource]="lessons">
    <ng-container matColumnDef="seqNo" >
        <th mat-header-cell *matHeaderCellDef>#</th>
        <td mat-cell *matCellDef="let lesson"> {{lesson.seqNo}} </td>
    </ng-container>

    <ng-container matColumnDef="description" >
        <th mat-header-cell *matHeaderCellDef>Description</th>
        <td mat-cell *matCellDef="let lesson"> {{lesson.description}} </td>
    </ng-container>

    <ng-container matColumnDef="duration" >
        <th mat-header-cell *matHeaderCellDef>Duration</th>
        <td duration-cell *matCellDef="let lesson"> {{lesson.duration}} </td>
    </ng-container>


    <th mat-header-row *matHeaderRowDef="displayedColumns">#</th>
    <tr mat-row *matRowDef="let lesson; columns:displayedColumns"></tr>

</table>

But when I tried to import MatTableModule in my app.module.ts, it gives me bunch of weird errors like the image that I have attached above.

This is my app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { initializeApp,provideFirebaseApp } from '@angular/fire/app';
import { environment } from '../environments/environment';
import { provideAuth,getAuth } from '@angular/fire/auth';
import { provideDatabase,getDatabase } from '@angular/fire/database';
import { provideFirestore,getFirestore } from '@angular/fire/firestore';
import { GameScreenComponent } from './game-screen/game-screen/game-screen.component';
import { HomeScreenComponent } from './home-screen/home-screen/home-screen.component';
import { ScoreboardScreenComponent } from './scoreboard-screen/scoreboard-screen/scoreboard-screen.component';
// import { MatTableModule } from '@angular/material/table'  

@NgModule({
  declarations: [
    AppComponent,
    GameScreenComponent,
    HomeScreenComponent,
    ScoreboardScreenComponent,
    
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    ReactiveFormsModule,
    // MatTableModule,
    provideFirebaseApp(() => initializeApp(environment.firebase)),
    provideAuth(() => getAuth()),
    provideDatabase(() => getDatabase()),
    provideFirestore(() => getFirestore()),
    // BrowserAnimationsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Can I please get some help on this? Below are parts of my errors when I import the MatTableModule in app.modules.ts (I got like 400 lines of errors like this, and most of them are related to cdk, but I don't think I used it in any of my project)

Error: node_modules/@angular/material/table/index.d.ts:178:18 - error TS2707: Generic type 'ɵɵComponentDeclaration' requires between 7 and 8 type arguments.


Error: node_modules/@angular/material/table/index.d.ts:188:18 - error TS2707: Generic type 'ɵɵDirectiveDeclaration' requires between 6 and 8 type arguments.


Error: node_modules/@angular/material/table/index.d.ts:198:18 - error TS2707: Generic type 'ɵɵComponentDeclaration' requires between 7 and 8 type arguments.


Error: node_modules/@angular/material/table/index.d.ts:382:18 - error TS2707: Generic type 'ɵɵComponentDeclaration' requires between 7 and 8 type arguments.



Error: src/app/scoreboard-screen/scoreboard-screen/scoreboard-screen.component.html:2:1 - error NG8001: 'mat-table' is not a known element:
1. If 'mat-table' is an Angular component, then verify that it is part of this module.
2. If 'mat-table' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.



Error occurs in the template of component ScoreboardScreenComponent.


Error: src/app/scoreboard-screen/scoreboard-screen/scoreboard-screen.component.html:2:46 - error NG8002: Can't bind to 'dataSource' since it isn't a known property of 'mat-table'.
1. If 'mat-table' is an Angular component and it has 'dataSource' input, then verify that it is part of this module.
2. If 'mat-table' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.

And this is the error when I don't import MatTableModule

Error: src/app/scoreboard-screen/scoreboard-screen/scoreboard-screen.component.html:2:52 - error NG8002: Can't bind to 'dataSource' since it isn't a known property of 'table'.
David Yoo
  • 11
  • 3
  • Have you tried using ` – mindparse Dec 06 '22 at 07:54
  • can you copy and paste the error to your question? – Owen Kelvin Dec 06 '22 at 07:56
  • I got like 400 lines of errors when I import the mat-lab – David Yoo Dec 06 '22 at 08:33
  • What is your angular version and angular material version in package.json? The error looks like there is a missmatch. I also assume that you installed angular material with npm? – Drazu Dec 06 '22 at 09:59
  • Angular CLI: 14.2.10 Node: 18.11.0 (Unsupported) Package Manager: npm 8.19.2 Angular: 14.2.12 ... animations, common, compiler, compiler-cli, core, forms ... platform-browser, platform-browser-dynamic, router Package Version --------------------------------- @angular-devkit/architect 0.1402.10 @angular-devkit/build-angular 14.2.10 @angular-devkit/core 14.2.10 @angular-devkit/schematics 14.2.10 @angular/cdk 15.0.1 @angular/cli 14.2.10 @angular/fire 7.5.0 @angular/material 15.0.1 @schematics/angular 14.2.10 rxjs 7.5.7 typescript 4.7.4 – David Yoo Dec 06 '22 at 21:50
  • This is the versions of my project. And I did install angular material with npm. – David Yoo Dec 06 '22 at 21:51

0 Answers0