value undefined in angular2

后端 未结 1 1048
广开言路
广开言路 2021-01-25 05:13

I am creating a application in which i am using the Ag-Grid api for listing my database content on the web page. Ag-grid have a predefined api to get the selected row content.

相关标签:
1条回答
  • 2021-01-25 05:33

    1) Use bind method to retain context this

    this.gridOptions.onSelectionChanged = this.onSelectionChanged.bind(this);
    

    2) You can also use Instance Function

    private onSelectionChanged = () => {
        console.log(this.gridOptions);
    }
    

    3) or inline arrow function

    this.gridOptions.onSelectionChanged = () => this.onSelectionChanged();
    
    0 讨论(0)
提交回复
热议问题