简体   繁体   English

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

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

This is no duplicate of any other questions about angular material table with this context. 在这种情况下,这与有关角形材料表的任何其他问题均无重复。 All these others refere to angular 2-5, not 6 所有其他这些是指角度2-5,而不是6

I'm getting this exception: 我收到此异常:

Can't bind to 'dataSource' since it isn't a known property of 'table'. 无法绑定到“数据源”,因为它不是“表”的已知属性。 (" (”

][dataSource]="dataSource" class="mat-elevation-z8"> ] [dataSource] =“ dataSource” class =“ mat-elevation-z8”>

If I remove [dataSource], the exception is the same, with the next specific directive. 如果删除[dataSource],则例外是相同的,使用下一个特定指令。

HTML 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 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 的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"
  },

It should work basically. 它应该基本工作。 But it doesn't. 但事实并非如此。 I have all dependencies updated and I imported the needed MatTableModule. 我已经更新了所有依赖项,并导入了所需的MatTableModule。 The code is from material.angular.io. 该代码来自material.angular.io。 I don't know what is wrong there. 我不知道那是怎么回事。

you do not need to use the tag table . 您不需要使用标签table just use 只是使用

<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>

and it should work 它应该工作

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

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