I have used angular 7.I am trying to expand and collapse table row by clicking name and place. But it is not opening properly. If i click place name, that place details only i want to show. But in my code it is opening all place details, Same for Name. How to resolve this issue.
app.component.html:
<table class="table">
<thead>
<th> Name </th>
<th> Place </th>
<th> Phone </th>
</thead>
<tbody>
<ng-container *ngFor="let data of data1">
<tr>
<td (click)="expanded1 = !expanded1"> <a href="javascript:void(0)">{{data.name}}</a> </td>
<td (click)="expanded2 = !expanded2"> <a href="javascript:void(0)">{{data.place}} </a></td>
<td> {{data.phone}} </td>
</tr>
<ng-container *ngIf="expanded1">
<tr>
<td colspan="3">
<div>Name Details:{{data.name}}</div>
</td>
</tr>
</ng-container>
<ng-container *ngIf="expanded2">
<tr>
<td colspan="3">
<div>Place Details:{{data.place}}</div>
</td>
</tr>
</ng-container>
</ng-container>
</tbody>
</table>
app.component.ts:
export class AppComponent {
expandContent = true;
expanded1 = false;
expanded2 = false;
data1 = [{
'name': 'john',
'place': 'forest',
'phone': '124-896-8963',
'expanded': false
}, {
'name': 'Jay',
'place': 'City',
'phone': '124-896-1234',
'expanded': false
}, {
'name': 'Joseph',
'place': 'sky',
'phone': '124-896-9632',
'expanded': false
},
]
}
Demo: https://stackblitz.com/edit/angular-3hylrt?file=src%2Fapp%2Fapp.component.html