【问题标题】:unknown properties of angular 6 <table mat-table>angular 6 <table mat-table> 的未知属性
【发布时间】:2019-01-26 13:24:05
【问题描述】:

这与有关此上下文的角度材料表的任何其他问题均不重复。所有这些其他都是指角度 2-5,而不是 6

我遇到了这个异常:

无法绑定到“dataSource”,因为它不是“table”的已知属性。 ("

][数据源]="数据源" 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。我不知道那里出了什么问题。

【问题讨论】:

  • 尝试将 更改为
  • 这是角度 5...这不适用于 6
  • 您确定在正确的模块中导入了MatTableModule
  • @enf0rcer 根据the documentation,OP 的语法是正确的。根据文档,mat-table 应作为&lt;table&gt; 元素的属性放置。
  • 你在使用惰性模块概念吗..??

标签: html angular typescript angular-material


【解决方案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>

它应该可以工作

【讨论】:

    猜你喜欢
    • 2019-04-05
    • 2020-01-11
    • 2018-03-19
    • 1970-01-01
    • 2019-04-07
    • 2019-10-10
    • 2019-08-31
    • 2019-05-11
    • 1970-01-01
    相关资源
    最近更新 更多