首页 文章

角度6 <table mat-table>的未知属性

提问于
浏览
0

这与上下文中关于角度材料表的任何其他问题没有重复 . 所有这些都引用角度2-5而不是6

我得到了这个例外:

无法绑定到'dataSource',因为它不是'table'的已知属性 . (“] [dataSource] =”dataSource“class =”mat-elevation-z8“>

如果我删除[dataSource],则异常与下一个特定指令相同 .

HTML

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

    <ng-container matColumnDef="ID">
      <th mat-header-cell *matHeaderCellDef> Id </th>
      <td mat-cell *matCellDef="let element"> {{element.ID}} </td>
    </ng-container>

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

app.module.ts

import {
    MatTabsModule,
    MatCardModule,
    MatInputModule,
    MatTableModule
} from "@angular/material";

@NgModule({
   declarations: [AppComponent, ProjektuebersichtComponent],
   imports: [
     BrowserModule,
     HazardRatingVerwaltungModule,
     AppRoutingModule,
     BrowserAnimationsModule,
     ServicesModule,
     MatTabsModule,
     MatCardModule,
     MatInputModule,
     MatTableModule
   ],
   providers: [],
   bootstrap: [AppComponent]
 })
 export class AppModule {}

package.json

"dependencies": {
    "@angular/animations": "^6.1.0",
    "@angular/cdk": "^6.4.5",
    "@angular/common": "^6.1.0",
    "@angular/compiler": "^6.1.0",
    "@angular/core": "^6.1.0",
    "@angular/forms": "^6.1.0",
    "@angular/http": "^6.1.0",
    "@angular/material": "^6.4.5",
    "@angular/platform-browser": "^6.1.0",
    "@angular/platform-browser-dynamic": "^6.1.0",
    "@angular/router": "^6.1.0",
    "core-js": "^2.5.4",
    "rxjs": "^6.0.0",
    "zone.js": "~0.8.26"
  },

它应该基本上起作用 . 但事实并非如此 . 我更新了所有依赖项,并导入了所需的MatTableModule . 代码来自material.angular.io . 我不知道那里有什么问题 .

1 回答

  • 1

    您不需要使用标签 table . 只是用

    <mat-table [dataSource]="dataSource"  class="mat-elevation-z8">
    
        <ng-container matColumnDef="ID">
          <th mat-header-cell *matHeaderCellDef> Id </th>
          <td mat-cell *matCellDef="let element"> {{element.ID}} </td>
        </ng-container>
    
       <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
       <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
    </mat-table>
    

    它应该工作

相关问题