Looking to extract and assign a JSON value obtained from an API into a variable. Here is an example:
TS
this.graphicService.getDatas().subscribe(datas => {
this.datas = datas;
console.log(datas);
});
test = this.datas[0].subdimensions[0].entry;
HTML
{{test}}
An error is displayed in the console:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'subdimensions' of undefined
TypeError: Cannot read property 'subdimensions' of undefined
at new GraphicsComponent (graphics.component.ts:33)...
However, it does function correctly if directly used in HTML as shown below:
{{datas[0]?.subdimensions[0].entry}}
The data will then print accurately. ..