V
V
Vyacheslav2019-02-25 12:34:33
Angular
Vyacheslav, 2019-02-25 12:34:33

How to show badge in ngFor loop by condition?

In general, I got confused in simple things ... There are two arrays:
1) persons with objects of type

{
name: "Brown",
personId: "dsfrauAUHjfrkf32"
}

2) badges
{
personId: "dsfrauAUHjfrkf32",
badge: true

In my component, the NgFor method displays a list of people. It is necessary to make it so that when this list is displayed, a badge is displayed next to the name if id and badge = true match.
That is, the difficulty for me is that the list of names in the component is formed from one array, and information on badges is stored in another.
This is done because these arrays are formed by subscription from different database collections. And now there is no time and desire to rewrite the database logic

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shai_hulud, 2019-02-25
@matu1

1) Bake it into a separate array with a new type that contains data from both collections
2) make an accessor on your hasBadge(personId: string) type component and pull it inside ngFor passing the id of the current element

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question