I have a content in a *ngFor loop. When I click on the content, like an accordion, I call a function passing the id of that object that returns the detail of the object. The problem is that now, when I click, It changes for each accordion and not separately. the html is
<div class="card" *ngFor="let data of datas" (click)="fetchData(data.dataId); data.expanded = !data.expanded" style="cursor:pointer; width: 100%;">
<div class="card-body" style="display:flex">
<h5 class="card-title">{{data.name}} </h5>
</div>
<ng-container *ngIf="data.expanded">
{{dataContent.descriptionDetail}}
</ng-container>
</div>
and in my component
fetchData(dataId:number) {
this.service.fetchData(dataId).subscribe(
(result) => {
this.dataContent = result;
console.log(result);
}
);
}
If I click in the first accordion, i get the correct dataContent. But if I click the second one, it gets me the second dataContent value correctly but also in the first accordion. Thanks