I am working in angular app where I am working on COVID 19 app.
Here I have 2 components where component A list of all the states and component B list all the district of the particular state.
Here is my stack blitz link stack blitz link
I want my output like this expected output
I got reference here from stack overflow stack overflow reference
Now I have displayed all the data of component in table format and when I click on that state it should load all the data of clicked state and when I click on that state again it should get closed. Also if I click on other state lists of all district fr that state should get displayed
But I don't know where to put my <app-componentB></app-componentB>
because if put it inside for loop and if I try to display list for one state it displays the same list of district under all states
Here is a piece of my code
componentA.html
<tbody *ngFor="let data of statewisedata;let i=index">
<span class="dropdown rotateDownRight"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg></span>
<tr class="state">
<td (click)="OngetState(data.state)" style="font-weight: 600;">{{data.state}}</td>
<td style="color: inherit;">{{data.confirmed}}
<span *ngIf='DailystateStatus[i]?.confirmed !==0 || DailystateStatus[i]?.confirmed < 0 ;' class="deltas" style="color: rgb(255, 7, 58);"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"></line><polyline points="5 12 12 5 19 12"></polyline>
</svg> {{DailystateStatus[i]?.confirmed}}</span>
</td>
<td style="color: inherit;">{{data.active}}</td>
<td style="color: inherit;">{{data.recovered}}</td>
<td style="color: inherit;">{{data.deaths}}</td>
</tr>
<app-district *ngIf="!showDistrict"></app-district>
</tbody>
componentA.ts
showDistrict=true
OngetState(state) {
this.cs.getState(state)
this.cs.getDataDistrictWise(state)
this.showDistrict=!this.showDistrict
}