0

I'm using ag-grid and reacting to some events I want to access to methods defined in the current componnet something like this:

@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....*

  },


 ..... 

};

So from the method: "onCellValueChanged" I need to call the method "methodToCall", using this here is wrong because the scope is different, but then How do I can accomplish that?

navy1978
  • 1,411
  • 1
  • 15
  • 35

2 Answers2

1

Try arrow function => like this -

onCellValueChanged = (params : DynamicComponentParams): void => {  
       *//I want from here to call the method "methodToCall"*
       this.methodToCall(null); *//this doesn't work....*

  },
The Head Rush
  • 3,157
  • 2
  • 25
  • 45
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
-1
 onCellValueChanged: (params : DynamicComponentParams) { 
       let vari = this.methodToCall(null); 
  },

try like this

Ram Ghadiyaram
  • 28,239
  • 13
  • 95
  • 121
Raviteja V
  • 454
  • 5
  • 11