【发布时间】:2019-06-07 20:33:50
【问题描述】:
我正在尝试将 Tabulator 用于 Angular 7 中的表格。我正在尝试在单击单元格时调用一个函数,以便该函数应该打开一个 MatDialog 框并显示行信息。但是,问题是当我尝试访问被调用函数内的任何组件变量(对话框:MatDialog)时,它是未定义的。在调试时,我发现该函数是在制表符内部调用的,而不是在角度组件中调用的。有没有办法在Angular中调用函数并访问函数内部的组件变量?
export class ExampleTableComponent implements OnInit {
exampleTable: Tabulator;
constructor(private dialog: MatDialog) { }
ngOnInit() {
this.exampleTable = new Tabulator("#ex-table-div",{
height : 300,
data: this.example_data,
layout: "fitColumns",
columns: [
{ formatter:"rownum", align:"center", width:40},
{ formatter: this.printIcon, width:40, align:"center",
cellClick: this.openDialog
},
.......
],
......
});
}
openDialog(e, cell){
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
this.dialog.open(DetailsComponent, {
width: '300px',
});
..........
}
......
}
【问题讨论】:
-
你试过 lamda 吗?
cellClick: () => this.openDialog() -
@Gilsdav:成功了!请解释一下你是如何找到修复的?谢谢
标签: angular angular-material angular7 tabulator