【问题标题】:cellRendererParams Ag-Grid 19 and Angular 6. Call function of my componentcellRendererParams Ag-Grid 19 和 Angular 6. 我的组件的调用函数
【发布时间】:2018-10-16 17:24:44
【问题描述】:

我的 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(){
}

【问题讨论】:

    标签: angular ag-grid


    【解决方案1】:

    这是一个上下文问题,downloadAttachmentAction 由 ag grid 调用,因此上下文是 ag-gird 实例,您需要做的是在调用该函数时更改上下文,绑定函数帮助我们这样做,更改方式正在使用 downloadAttachmentAction:

        action: this.downloadAttachmentAction
    

        action: this.downloadAttachmentAction.bind(this)
    

    【讨论】:

    • 这对我不起作用,在我的情况下唯一的区别不是控制器功能,而是我从本地文件读取的 otherFunction() 调用服务,我想删除一个对象从与我的 param.node.data 匹配的文件中,但是当我从上面提到的 otherFunction() 中的文件中读取时看到未定义。
    猜你喜欢
    • 2021-03-13
    • 2018-11-27
    • 2020-09-02
    • 2019-03-19
    • 2019-03-16
    • 1970-01-01
    • 2019-01-24
    • 2017-04-29
    • 2021-11-13
    相关资源
    最近更新 更多