Reputation: 1651
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;
});
}
}
Upvotes: 2
Views: 1217
Reputation: 1277
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;
});
}
}
Upvotes: 4