I have encountered an issue with a single Angular 2 service:
validate() {
return this.http.get('api/validate', data); }
Consuming the API works fine:
this.ValidationService.validate().subscribe(result => {
console.log('data returned from api', result);
});
The result is an object:
{status: "success", data: {…}}
However, when trying to access the data property directly:
this.ValidationService.validate().subscribe(result => {
console.log('data returned from api', result.data);
});
This results in Typescript throwing a compilation error as it cannot find the data property. Oddly enough, checking for the presence of 'data'
returns true
:
this.ValidationService.validate().subscribe(result => {
console.log('data returned from api', result.hasOwnProperty('data'));
});
Even trying result['data']
does not work. Any thoughts on what might be causing this unexpected behavior?