从内部方法调用方法
call a method from an inner Method
我正在使用 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",这里使用这个是错误的,因为范围不同,但是我该如何实现呢?
像这样尝试箭头函数=>
-
onCellValueChanged = (params : DynamicComponentParams): void => {
*//I want from here to call the method "methodToCall"*
this.methodToCall(null); *//this doesn't work....*
},
onCellValueChanged: (params : DynamicComponentParams) {
let vari = this.methodToCall(null);
},
这样试试
我正在使用 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",这里使用这个是错误的,因为范围不同,但是我该如何实现呢?
像这样尝试箭头函数=>
-
onCellValueChanged = (params : DynamicComponentParams): void => {
*//I want from here to call the method "methodToCall"*
this.methodToCall(null); *//this doesn't work....*
},
onCellValueChanged: (params : DynamicComponentParams) {
let vari = this.methodToCall(null);
},
这样试试