1

I need to render a json object that is the output of a webapi call on a component.

The problem is that this response has not a fixed structure, it can change depending on the webapi execution.

Sometimes it can be a simple array, other time an array of object etc...

How can I render it without knowing the output structure ?

For who comes from PHP development, I need like something like print_r function...

Thanks Regards

1 Answer 1

3

It depends on how you want to render it.

To debug you can use the json pipe

{{data | json}}

Otherwise you could check if the returned response is an array or an object and render it based on that.

if (Array.isArray(data)) {
  // render as array
} else {
  // render as something else
}

I would probably try to normalize the datastructure that is returned from an angular service so that it's always an array of objects, and then based on if the objects contain different keys render it differently.

Sign up to request clarification or add additional context in comments.

1 Comment

{{data | json}} is what I was searching for! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.