I'm trying to toggle an element to show/hide when I click on the title. So far I have this approach
<div class="parent" (click)="status=!status" [ngClass]="status ? 'hide' : 'display'">
<div class="child">
<p>Info to show or hide</p>
</div>
</div>
On CSS file I have this
.hide .child {
display: none;
}
This works fine for what I need when I have one element. But I want to display several of this items with an *ngFor. When I do that, then variable status
is shared and clicking on any of the other elements will toggle all of them. Since the creation of elements is dynamic, is there any way to limit the scope of status
variable to just that element? Or is there a better approach to this?