代码之家  ›  专栏  ›  技术社区  ›  Jose

cellRenderParams Ag Grid 19和Angular 6。调用我的组件的函数

  •  0
  • Jose  · 技术社区  · 8 年前

    我到达我的控制器没有问题,但当试图调用我的控制器的另一个函数时,我不能,因为当我把这个,它不是指我的控制器,而是指ag网格组件。

    //组成部分

    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(){
    }
    
    1 回复  |  直到 8 年前
        1
  •  3
  •   Ritesh Waghela    8 年前

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

        action: this.downloadAttachmentAction
    

    到

        action: this.downloadAttachmentAction.bind(this)