2

So, there is an object, inside which there are some other objects, and inside them there are more objects. Please, tell me how to output key values. I suppose *ngFor won't help

const data = {
    first_data: {
      id: "1",
      name: "First",
      type: "Administration",
      sections: {
        main_section: {
            id: "main_section",
            name: "Main Section",
            sub_sections: {
                sub_first: {
                    id: "12",
                    name:  "Subsection_name",
                    questions: {
                      first_question: {
                        id: "44",
                        name: "Answer"
                      },
                      second_question: {
                        id: "33",
                        name: "True"
                      }
                    }
                  }
                }
              }
            }
          }
        }
1
  • 3
    Quite a horrible format :-). You could use a keyvalue pipe in an ngFor I guess? Commented Jul 14, 2021 at 13:12

1 Answer 1

3

Use ngFor combined with KeyValuePipe:

Transforms Object or Map into an array of key value pairs.

<div *ngFor="let item of object | keyvalue">
  {{item.key}}:{{item.value}}
</div>

However, I guess you need some kind of custom pipe to transform your data. I found this thread including this answer - maybe worth a try.

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

Comments

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.