API CALL
tmp:any;
getData(){
this.api.getFiles().subscribe((res)=>{
console.log(res);
this.tmp=res;
})
}
Here I am able to get data from Api when i use console to check response then it is showing correct result but when i assign it a variable and accessing variable showing undefined. this is data
{
"files":[
{
"id":23,
"name": "file3",
"path":"",
"status": "processed",
"annotation": "manual",
"uploadedTime": "12-10-2012 10:24:14",
"size": 10.23,
"children":[]
}
]
}
CodePudding user response:
I was trying access variable in ngOnIt till that variable is not initialized.So getting undefined. refer here