Reputation: 1819
I have in my Ag-grid column a column in which I have inserted a component, that pusal calls me to a function of my controller.
I get to my controller without problem, but when trying to call another function of my controller, I can not, because when I put this, it does not refer to my controller, but to the ag-grid component.
// COMPONENT
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(){
}
Upvotes: 0
Views: 4631
Reputation: 3727
This is a context issue, the downloadAttachmentAction is called by ag grid and hence the context is ag-gird instance, what you need to do is change the context when that function is invoked, bind function help us do this, change how the downloadAttachmentAction is being used from:
action: this.downloadAttachmentAction
to
action: this.downloadAttachmentAction.bind(this)
Upvotes: 4