Typescript : AngularJS retrieving a result object -
i have angularjs service in typescript makes https call returns data. results child object of response.data follows response.data.result.
how access it? cannot response.data.result compile time error response.data defined under ihttppromisecallbackarg<t> not have 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; }); } }
after this.$http.get(this.webapiurl + '/api/applications'), try changing ng.ihttppromisecallbackarg<iapplication[]> { 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; }); } }
Comments
Post a Comment