Glenn Utter Glenn Utter - 1 year ago 149
JSON Question

Angular 2: Access object data

In my Angular RC2 app I make an observable HTTP call that returns the following JSON to me from the API:

"Type": 1

I map the data like this:

(data) => {
this.details = data.Details;
this.type = data.Type;
(error) => {

How do I access the values inside the "Details" object from here?

I tried:


But that won't work and I can't use ngFor to loop it either.

Answer Source

You could use the Elvis operator for this:


As a matter of fact, you load your data asynchronously so details is undefined at the beginning.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download