I have a class Vehicle ,in which i have method called getTorque(name:string) based on the vehicle name passed i am calling an API to retrieve the data. After retrieving the data i need to do call some call back function to load the data in html.Sample implementation below
class B {
public getData(): JQueryPromise<Response> {
return super.get<Response>(url); // get method is nothing but Jquery ajax get method Asynchronous is true and we dont have control over it.
}
}
class A extends B {
public respValue: string = '';
public getTorque() {
let b = new B();
b.getData().done((respObj: Response) => {
this.respValue = respObj.id;
});
}
}
Here my problem is this.respValue is coming as undefined.If i make my asynchronous to false it is assigning the value. Could you please explain me how jquery promises can be handled in case of asynchronous calls