繁体   English   中英

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

[英]unknown properties of angular 6 <table mat-table>

在这种情况下,这与有关角形材料表的任何其他问题均无重复。 所有其他这些是指角度2-5,而不是6

我收到此异常:

无法绑定到“数据源”,因为它不是“表”的已知属性。 (”

] [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。 我不知道那是怎么回事。

您不需要使用标签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>

它应该工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM