angular 6 <table mat-table>的未知属性 [英] unknown properties of angular 6 <table mat-table>

查看:23
本文介绍了angular 6 <table mat-table>的未知属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我收到此异常:

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

Can't bind to 'dataSource' since it isn't a known property of 'table'. ("

][数据源]="数据源"class="mat-elevation-z8">

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

如果我删除 [dataSource],异常是一样的,有下一个特定指令.

If I remove [dataSource], the exception is the same, with the next specific directive.

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.我不知道那里出了什么问题.

It should work basically. But it doesn't. I have all dependencies updated and I imported the needed MatTableModule. The code is from material.angular.io. I don't know what is wrong there.

推荐答案

你不需要使用标签 table.只需使用

you do not need to use the tag 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>

它应该可以工作

这篇关于angular 6 &lt;table mat-table&gt;的未知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆