K
K
Konstantin2021-02-13 01:12:55
Angular
Konstantin, 2021-02-13 01:12:55

How would you create an object?

I receive data from the server - an array of categories: interface Category { id: number, name: string, items: []}

I want to create a group based on each category, because the category has items: [], so that the group works as a dropdown element - opens and hides on click.

Imagine that the group is defined as follows: interface Group { id: number, name: elements: []}.

Suppose that in the parent component I get the categories:

public categories$: Observable<Category[]>;

And in the template of this component I display the categories in a group:

<app-category-group *ngFor="let cat of categories$  | async"></app-category-group>


How not to mix types Categoryand Grouphow to make it so that no matter what the content is in Group. Where to do it - in the parent after receiving the categories - to convert to another type? At the same time, I do not want to mutate the original data

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question