我正在使用ag-grid并对某些事件做出反应,我想访问当前组件中定义的方法,如下所示:
@Component({
selector: 'whatever',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit, OnDestroy{
...
methodToCall(params : any){
return 1;
}
gridOptions = {
onCellValueChanged: function(params : DynamicComponentParams){
*//I want from here to call the method "methodToCall"*
this.methodToCall(null); *//this doesn't work....*
},
.....
};
因此,从方法:“ onCellValueChanged”开始,我需要调用方法“ methodToCall”,在此使用此方法是错误的,因为范围有所不同,但是那我该如何实现呢?
答案 0 :(得分:1)
像这样尝试箭头功能=>
-
onCellValueChanged = (params : DynamicComponentParams): void => {
*//I want from here to call the method "methodToCall"*
this.methodToCall(null); *//this doesn't work....*
},
答案 1 :(得分:-1)
onCellValueChanged: (params : DynamicComponentParams) {
let vari = this.methodToCall(null);
},
尝试这样