G
G
Galdar Turin2020-05-27 11:46:47
Angular
Galdar Turin, 2020-05-27 11:46:47

How to iterate over an object with arrays in Angular?

I would like to iterate over the objects:

objects

Без группы: Array(3)
0: {ID: "21", NAME: "Ксения", LAST_NAME: "Овдина", TYPE_ID: null, SOURCE_ID: null, …}
1: {ID: "17", NAME: "Константин", LAST_NAME: "Петриченко", TYPE_ID: null, SOURCE_ID: "SELF", …}
2: {ID: "8", NAME: "Сергей", LAST_NAME: "", TYPE_ID: null, SOURCE_ID: "SELF", …}
Клиенты: [{…}]
Новое тестовое поле: (2) [{…}, {…}]
Общие контакты: (4) [{…}, {…}, {…}, {…}]
Поставщики: [{…}]


and display arrays of these objects in HTML form.
Or do you still have to group them into separate arrays first for *ngFor to work?

Maybe someone knows tricks to iterate over such an object and output data!
Basically I want to do something like this:
<ul>

            <li>Без группы
                <ul>
                    <li>Ксения</li>
                    <li>Алексей</li>
                    <li>Вадим</li>
                </ul>
            </li>

            <li>Новое тестовое поле
                <ul>
                    <li>Вова</li>
                    <li>...</li>
                    <li>...</li>
                </ul>
            </li>

            <li>Клиенты</li>

        </ul>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Galdar Turin, 2020-05-27
@Galdar

That's what I needed!
https://angular.io/api/common/KeyValuePipe

<ul *ngFor="let item of listContact | keyvalue">
                {{item.key}}
                <li *ngFor="let contact of item.value">{{ contact.NAME }}</li>
            </ul>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question