S
S
sdgroup142018-02-11 19:43:47
JavaScript
sdgroup14, 2018-02-11 19:43:47

What is the correct way to output json via *ngFor?

There is an array:


[
{
"car": "Auto1",
"Category": "B",
},
{
"car": "Auto2",
"Category": "B",
},
{
"car": "Auto3",
"Category ": "B"
},
{
"car": "Auto4",
"Category": 'A'
},
{
"car": "Auto5",
"Category": false
}
]

How to correctly display it through ngFor is not just , but so that each object is filtered by the "category" key from the array.
Conclusion There should be 3 types:
1) if the category is entered in the object, for example, the category "B", but it was not there before, then create a category and put this object there.
2) if the category is entered in the object, for example, the category "B", and before it was, then put this object into the previously existing category "VE.
3) and if the category is not entered "false", then simply put this object in the container where all categories (i.e. in the root container)
The DOM structure, following the example from the JSON written above, after this iteration should end up like this:
-Auto 5 (no category)
How do I make ngFor according to the above conditions? What to write in the component and what in html
5a80944c1d64c786489615.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Ander, 2018-02-11
@loktionov129

https://stackblitz.com/edit/angular-jxjgow
D8KWpKxYliM.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question