cellRendererParams Ag-Grid 19 and Angular 6.调用我组件的函数
cellRendererParams Ag-Grid 19 and Angular 6. Call function of my component
我在我的 Ag-grid 列中有一个列,我在其中插入了一个组件,那个 pusal 调用我到我的控制器的一个功能。
我可以毫无问题地访问我的控制器,但是当我试图调用我的控制器的另一个函数时,我不能,因为当我放置它时,它不是指我的控制器,而是指 ag-grid 组件。
// 组件
this.columnDefs = [{
headerName: '',
width: 50,
cellRendererFramework: ActionCellRendererComponent,
cellRendererParams: {
icon: 'fa-trash',
action: this.downloadAttachmentAction
}
},
downloadAttachmentAction(params: any) {
this.otherFunction() <-- I can not do the functions of my controller. with "this" as it refers to ag-grid
}
otherFunction(){
}
这是一个上下文问题,downloadAttachmentAction 被 ag grid 调用,因此上下文是 ag-gird 实例,您需要做的是在调用该函数时更改上下文,绑定函数帮助我们做到这一点,更改 downloadAttachmentAction 的使用方式:
action: this.downloadAttachmentAction
到
action: this.downloadAttachmentAction.bind(this)
我在我的 Ag-grid 列中有一个列,我在其中插入了一个组件,那个 pusal 调用我到我的控制器的一个功能。
我可以毫无问题地访问我的控制器,但是当我试图调用我的控制器的另一个函数时,我不能,因为当我放置它时,它不是指我的控制器,而是指 ag-grid 组件。
// 组件
this.columnDefs = [{
headerName: '',
width: 50,
cellRendererFramework: ActionCellRendererComponent,
cellRendererParams: {
icon: 'fa-trash',
action: this.downloadAttachmentAction
}
},
downloadAttachmentAction(params: any) {
this.otherFunction() <-- I can not do the functions of my controller. with "this" as it refers to ag-grid
}
otherFunction(){
}
这是一个上下文问题,downloadAttachmentAction 被 ag grid 调用,因此上下文是 ag-gird 实例,您需要做的是在调用该函数时更改上下文,绑定函数帮助我们做到这一点,更改 downloadAttachmentAction 的使用方式:
action: this.downloadAttachmentAction
到
action: this.downloadAttachmentAction.bind(this)