O
O
Ole892018-12-25 17:16:02
Angular
Ole89, 2018-12-25 17:16:02

How to configure the correct display of tags?

There is a news feed. Each news has a list of tags. It appears when you click on the "Tags" button, which is located next to each of the news and, accordingly, disappears when you click this button again.
How can I make it so that clicking on "Tags" opens only the list of tags for the given news item, and not the list of tags for each of the news items? I understand that this is happening, since the showNewsTag variable is the same for all news. But if you refuse it, then what about *ngIf then?
I am attaching the code.

<div *ngFor="let item of news">
<p> {{item.title}} </p>
<p> {{item.content}} </p>
<span (click)="showNewsTag = !showNewsTag">Теги:</span>
<div *ngIf="showNewsTag">
<div name="tags" *ngFor="let tag of tags">
<span> {{tag.title}} </span>
</div>
</div>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-12-25
@Ole89

Let each news have its own property responsible for displaying tags:

<span (click)="item.showTags = !item.showTags">Теги:</span>
<div *ngIf="item.showTags">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question