2

I have a AngularJS service in Typescript that makes a get https call returns some data. My results is a child object of the response.data as follows response.data.Result.

How do I get access to it? I cannot do response.data.Result as I get compile time error where the response.data defined under IHttpPromiseCallbackArg<T> does not have the result property.

 class ApplicationService implements IApplicationService {
        private webApiUrl;
        static $inject = ['$http'];

        constructor(private $http: ng.IHttpService) {
            this.webApiUrl = 'http://localhost';
            this.$http = $http;
        }

        getApplications(): ng.IPromise<IApplication[]> {
            return this.$http.get(this.webApiUrl + '/api/applications')
                .then((response: ng.IHttpPromiseCallbackArg<IApplication[]>): IApplication[]=> {
                return <IApplication[]>response.data;
            });
        }
    }
1
  • Print response. What does it show? Commented May 30, 2015 at 20:05

1 Answer 1

4

After this.$http.get(this.webApiUrl + '/api/applications'), try changing from ng.IHttpPromiseCallbackArg<IApplication[]> to { data: { Result: IApplication[] } } type.

class ApplicationService implements IApplicationService {
    private webApiUrl;
    static $inject = ['$http'];

    constructor(private $http: ng.IHttpService) {
        this.webApiUrl = 'http://localhost';
        this.$http = $http;
    }

    getApplications(): ng.IPromise<IApplication[]> {
        return this.$http.get(this.webApiUrl + '/api/applications')
        .then((response: { data: { Result: IApplication[] } }): IApplication[]=> {
            return response.data.Result;
        });
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.