0

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

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
Krishna
  • 39
  • 9
  • You will have to show us the `get()` method. Chances are you are not doing something correctly in that method (like returning the promise). – jfriend00 Aug 25 '16 at 02:23
  • Thanks for the url .That really helped me to understand the concepts of promise and other information related to Ajax – Krishna Aug 31 '16 at 09:16

0 Answers0