0
var arr=[
        {Key0: "myValue1"},
        {Key0: "myValue2"},
        {Key0: "myValue3"},
        {Key1: "myValue4"},
        {Key2: "myValue5"}, ]

from the above array, I want to get the values using its key in *ngFor angular, for example, key0 values I want to display along with other values values,

I have also tried like this but can't able to get the desired output

                         <li mat-list-item *ngFor='let C of arr'>
                             {{C}}</li>

Note:

I tried like {{c.key0}} but it prints only key0 values, but here I want all the values like key1,key2

thanks in advance.

4

2 Answers 2

1

I think you should modify your array in typescript first by using iteration logic. And then show it using *ngFor.

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

Comments

1

As shown in: How to iterate object keys using *ngFor

You can use (angular v6+):

<div *ngFor='let C of arr | keyvalue">
   {{C.key}}:{{C.value}}
</div>

4 Comments

I tried using {{c.value}}, but i'm getting [object:object] @Swoox
any other fix for {{c.value}} to get the values
@sivaIT You can use {{c.value | json}} to show the object, then select which exact field you want from it, or add a custom toString() method to it.
@sivaIT Ohh sorry I see your array is different. <div *ngFor='let C of arr[0] | keyvalue"> or you make this.arr = { {Key0: "myValue1"} }

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.