Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在mat对话框中显示mat表格_Angular_Angular Material_Angular8_Angular Material 7 - Fatal编程技术网

Angular 在mat对话框中显示mat表格

Angular 在mat对话框中显示mat表格,angular,angular-material,angular8,angular-material-7,Angular,Angular Material,Angular8,Angular Material 7,在mat对话框中使用mat表格时,我无法显示mat表格内容。我可以在DOM中看到正确数量的“tr”,但它们是空的 你能告诉我我做错了什么吗 .html 第1列 {{element.feature} 第2列 {{element.version} .ts @Component({selector: 'dialog-overview-example-dialog', templateUrl: 'dialog-overview-example-dialog.html', }) export c

在mat对话框中使用mat表格时,我无法显示mat表格内容。我可以在DOM中看到正确数量的“tr”,但它们是空的

你能告诉我我做错了什么吗

.html


第1列
{{element.feature}
第2列
{{element.version}
.ts

 @Component({selector: 'dialog-overview-example-dialog',
  templateUrl: 'dialog-overview-example-dialog.html',
})
export class DialogOverviewExampleDialog implements OnInit {
  public versions: any[] = [];
  public versionIndex: number = 0;
  constructor(
    public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
    @Inject(MAT_DIALOG_DATA) public data: DialogData) {}

  onNoClick(): void {
    this.dialogRef.close();
  }

ngOnInit(){
      var toAdd = {
        num: "1",
        date: "01/10/2019",
        datas: []
      };
      toAdd.datas.push({
        feature:"feature 1",
        version:""
      }); 
      toAdd.datas.push({
        feature:"feature 2",
        version:"0.2"
      }); 
      toAdd.datas.push({
        feature:"feature 3",
        version:"0.3"
      }); 
      toAdd.datas.push({
        feature:"feature 4",
        version:""
      }); 
      this.versions.push(toAdd);

  }
}
@Component({selector:'dialog overview example dialog',
templateUrl:'dialog overview example dialog.html',
})
导出类对话框概述示例对话框实现OnInit{
公共版本:任意[]=[];
公共版本索引:编号=0;
建造师(
公共dialogRef:MatDialogRef,
@注入(MAT_DIALOG_DATA)公共数据:DialogData{}
onNoClick():void{
this.dialogRef.close();
}
恩戈尼尼特(){
变量toAdd={
数字:“1”,
日期:“2019年10月1日”,
数据:[]
};
toAdd.datas.push({
功能:“功能1”,
版本:“”
}); 
toAdd.datas.push({
功能:“功能2”,
版本:“0.2”
}); 
toAdd.datas.push({
功能:“功能3”,
版本:“0.3”
}); 
toAdd.datas.push({
功能:“功能4”,
版本:“”
}); 
这个.versions.push(toAdd);
}
}


添加
displayedColumns:string[]=['feature','version']到对话框组件

@Component({
  selector: 'dialog-overview-example-dialog',
  templateUrl: 'dialog-overview-example-dialog.html',
})
export class DialogOverviewExampleDialog implements OnInit {
  public versions: any[] = [];
  public versionIndex: number = 0;
  displayedColumns: string[] = ['feature', 'version'];

您忘记定义
displayedColumns
数组。添加此
公共显示列=['feature','version']0.2小时。。。。需要更多的咖啡。。。非常感谢@FabianKüngo如果已经指定了值,则不必指定变量的类型。(例如,
displayedColumns:string[]=[/*…*/];
应该是
displayedColumns=[/*…*/]
@Component({
  selector: 'dialog-overview-example-dialog',
  templateUrl: 'dialog-overview-example-dialog.html',
})
export class DialogOverviewExampleDialog implements OnInit {
  public versions: any[] = [];
  public versionIndex: number = 0;
  displayedColumns: string[] = ['feature', 'version'];