I have an angular component that I will fillout based on an API call to a Nodejs server.
This API returns an object sort of like this:
{
"data": {
"firstname": "John",
"lastname": "Doe",
"age": 34
}
}
So I create at the TS:
public data: any={};
And then I call the API at ngOnInit, which populates data.
My problem is that at the HTML file, when I want to print lets say data.firstname:
Your name is {{data.firstname}}
Im getting this error:
TypeError: undefined is not an object (evaluating ctx.data.firstname)
I've learn that if I print the name as follows, that error won't show up:
Your name is {{data?.firstname}}
But it doesn't work in all cases.
Is there a way to fix this issue? The application works fine; I just dont like to see the errors on the console. Im planning to build this application the cleanest possible way.
thanks.
{{data.data.firstname}}