I have an interface defining my data object as below:
export interface Iemployee {
fileName: string;
empData: IempData }
export interface IempData {
data: string;
}
I was trying to retrieve a json object using observables .I could successfully load the object but unable to access any of the properties. I could see the object log in console ,but when I try to log the property I see undefined error.Also I could access properties during runtime in debug window but cant assign to a variable.Please help. Below is my service and component code.
Service Code:
downloadFile(): Observable<Iemployee > {
return this._http.get<Iemployee >(this._url)
.map(response => {
return response as Iemployee;
})
.catch(this.handleError);
}
Component Code:
downLoadFile() {
this._employeeService.downloadFile().subscribe(response => {
this.empData = response;
console.log(response );// object logged successfully
console.log(response.fileName); // undefined but can see it during debugging with a watch
console.log(this.empData ); //can log
console.log(this.empData .fileName);// undefined
}, Error => {
console.log(Error);
});
}