1

I am using angular 7 and I am displaying some data.

Here are the parts:

myData: any;

The content of myData is:

{
    "id" : "1",
    "name" : "Name 1",
    "stuff" : [ 
        {
            "cmd" : "something here"
        }, 
        {
            "cmd" : "something else here"
        }
    ]
}

Then is my app.component.html I have:

<ul class="code-editor-options-menu" *ngFor="let dat of myData">
  <li>
    <span>{{dat.name}}</span>
    <span aria-hidden="true">{{dat.stuff.cmd}}</span>
  </li>
</ul>

With this: {{dat.stuff.cmd}} I'm trying to list all of the items inside stuff.

How can I do that?

1
  • What is your myData? Is it a single JSON as you shown or is it actually an array of objects? Commented Apr 16, 2019 at 8:47

1 Answer 1

2

name is not part of stuff, so you cannot iterate

check this snippet: your example

component:

  myData = {
    "id": "1",
    "name": "Name 1",
    "stuff": [
      {
        "cmd": "something here"
      },
      {
        "cmd": "something else here"
      }
    ]
  }

view:

<ul class="code-editor-options-menu" *ngFor="let dat of myData.stuff">
  <li>
    <span>{{myData.name}}</span>
    <span aria-hidden="true">{{dat.cmd}}</span>
  </li>
</ul>
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.