首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mat-table不打印Angular 5中的数据

Mat-table不打印Angular 5中的数据
EN

Stack Overflow用户
提问于 2017-12-08 17:03:10
回答 0查看 3.1K关注 0票数 0

我会在我的项目中使用mat-table

在我的组件文件中,我使用observable从DB捕获数据并将它们打印到我的数据表中。

我尝试按照official tutorial进行操作,但屏幕上什么也没有打印出来,也没有出现错误

代码语言:javascript
复制
export class ListeProjetsComponent implements OnInit {

  constructor(private ajoutProj: AjoutprojService) { }
  nouveauProjet: NouveauProjet[];
  ngOnInit(){
    this.getAllProj();
  }
  displayedColumns = ['name'];
  dataSource = new MatTableDataSource<NouveauProjet>(this.nouveauProjet);

  applyFilter(filterValue: string) {
    filterValue = filterValue.trim(); // Remove whitespace
    filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
    this.dataSource.filter = filterValue;
  }

  getAllProj() {
    this.ajoutProj.getAllProj().subscribe(
      response => {
      this.nouveauProjet = response; console.log(this.nouveauProjet) // data is printed in the browser console. but not on screen
      },
      error => console.log(error)
    );
  }
}

Html文件

代码语言:javascript
复制
<div class="example-container mat-elevation-z8">
  <div class="example-header">
    <mat-form-field>
      <input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
    </mat-form-field>
  </div>

  <mat-table #table [dataSource]="dataSource">

    <ng-container matColumnDef="name">
      <mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
      <mat-cell *matCellDef="let element"> {{element.nomProj}} </mat-cell>
    </ng-container>



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

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47710862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档