Why am I experiencing errors in the console when trying to set the API return to a variable? How can this issue be resolved?
This is my TypeScript code:
public myData = new myDataModel();
getData(){
this.myCoolService.getDataAPI()
.subscribe((res) => {
this.myData = res['financialInformationBean'][0];
});
}
This is what my API returns:
{
"code":0,
"financialInformationBean":[
{
"name":{
"value":"abc"
},
"color":{
"value":"green"
}
}
]
}
This is my model:
export class myDataModel {
name: Value;
color: Value;
}
export interface Value {
value: string;
}
Here is how it appears in my HTML:
<span>{{ myData.name.value }}</span>
The console outputs:
WalletComponent.html:30 ERROR TypeError: Cannot read property 'value' of undefined
I have also tried this in my HTML, which did not show any errors but displayed [Object] [Object]
on my page:
<span>{{ myData.name}}</span>