Javascript Mat表格不打印角度5中的数据
我会在我的项目中使用Javascript Mat表格不打印角度5中的数据,javascript,angular,angular-material,Javascript,Angular,Angular Material,我会在我的项目中使用mat table 在我的组件文件中,我使用observable从DB捕获数据,并将它们打印到数据表中 我试着按照指示去做,但屏幕上什么也没印出来,我没有发现错误 export class ListeProjetsComponent implements OnInit { constructor(private ajoutProj: AjoutprojService) { } nouveauProjet: NouveauProjet[]; ngOnInit(){
mat table
在我的组件文件中,我使用observable从DB捕获数据,并将它们打印到数据表中
我试着按照指示去做,但屏幕上什么也没印出来,我没有发现错误
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)
);
}
}
导出类ListProjetComponent实现OnInit{
构造函数(私有AjoupProj:AjoupProJService){}
nouveauProjet:nouveauProjet[];
恩戈尼尼特(){
这个.getAllProj();
}
displayedColumns=['name'];
dataSource=新MatTableDataSource(this.nouveauProjet);
applyFilter(filterValue:string){
filterValue=filterValue.trim();//删除空白
filterValue=filterValue.toLowerCase();//MatTableDataSource默认为小写匹配
this.dataSource.filter=filterValue;
}
getAllProj(){
这是.ajoupproj.getAllProj().subscribe(
响应=>{
this.nouveauProjet=response;console.log(this.nouveauProjet)//数据在浏览器控制台中打印,但不在屏幕上打印
},
error=>console.log(错误)
);
}
}
Html文件
<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>
名称
{{element.nomProj}
这可能是因为您使用空数据集初始化了表:
dataSource = new MatTableDataSource<NouveauProjet>(this.nouveauProjet);
这可能是因为您使用空数据集初始化表:
dataSource = new MatTableDataSource<NouveauProjet>(this.nouveauProjet);
这对我不起作用,也没有错误消息。正确显示空行,但行上没有数据。数据来查看。我有同样的问题,行显示,但没有数据。有什么建议吗?这对我不起作用,也没有错误消息。正确显示空行,但行上没有数据。数据来查看。我有同样的问题,行显示,但没有数据。有什么建议吗?