1

Im new to angular and struggling to display nested json object in select dropdown. This is my json object.

[
  { 
    "cuisine":{ 
      "cuisine_id":1035,
      "cuisine_name":"Afghan"
    }
  },
  { 
    "cuisine":{ 
      "cuisine_id":1,
      "cuisine_name":"American"
    }
  }
]

And in my component HTML im displaying like this

<select class="form-control dropdown" name="processTemplate" id="processTemplate">
  <option *ngFor="let cuisineList of cusine1 | keyvalue">
     {{ cuisineList.value.cuisine_name | json }}
   </option>
 </select>  

I would like to display only cuisine_name in select dropdown. Not sure where im going wrong. Any help is much appreciated

2
  • Is the posted JSON is a valid one? Commented Jan 7, 2020 at 9:20
  • Yes @PrashantPimpale Commented Jan 7, 2020 at 9:26

3 Answers 3

1

Use:

{{ cuisineList.value.cuisine.cuisine_name }}

since you need to access cuisine_name of each cuisine object .

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

1 Comment

a little correctionn cuisineList.value.cuisine.cuisine_name as she is using keyvalue pipe
0

Try like this:

<select class="form-control dropdown" name="processTemplate" id="processTemplate">
  <option *ngFor="let cuisineList of cusine1 | keyvalue">
     {{ cuisineList.value.cuisine.cuisine_name }}
  </option>
</select>

Working Demo

Comments

0

Grab the json array in a variable. Let's the variable is cuisines. Now Follow the snippet.

<select class="form-control dropdown" name="processTemplate" id="processTemplate">
  <option *ngFor="let cuisineList of cuisines">
     {{ cuisineList.cuisine.cuisine_name}}
   </option>
 </select> 

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.