1

I'm using angular devexpress version. In my form i have dxselectbox, it has onselectionchanged event function to get the selected value. I can able to get the value but in the call back function i can't able to access another method are global declared variable it shows undefined.

products : any[];
.....
onSelectionChangedCallback(event){
 let value = event.selectedItem;
this.test(); // shows undefined
this.products; // shows undefined
}

test(){
alert('');
}

What is the issue ? Please help

Tomislav Stankovic
  • 3,080
  • 17
  • 35
  • 42
Kerin
  • 23
  • 1
  • 5
  • this.test() is saying - call a method named test that is located in this method. I think it would be enough if you call that method without this. Also, why don't you open developer consol and put couple of breakpoints there and see what's going on. – Robert May 04 '18 at 08:08
  • You should be able to call any method in your component because onSelectionChangedCallback and test are in the same scope. You are doing nothing with the 'this.products' property. where do you see undefined? – Jesus Gilberto Valenzuela Aug 29 '18 at 23:16

1 Answers1

0

I think your Problem is related to this ticket: https://supportcenter.devexpress.com/ticket/details/t487497/dxform-how-to-reach-a-service-within-onvaluechanged-handler-in-angular-2

The problem is that inside the callback function this references the devexpress-widget and not your angular-component.

The fix would be to bind this to the callbackFunction when you assing onSelectionChangedCallback to the onselectionchanged-Event.

onselectionchanged: onSelectionChangedCallback.bind(this)

Based on your provided code I dont know where it happens exactly in your case

Devextreme-Documentation: https://js.devexpress.com/Documentation/Guide/Angular_Components/Component_Configuration_Syntax/#Callback_Functions