2 回答

TA貢獻1785條經驗 獲得超8個贊
you need to do a few changes and your code is
**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); showHideData(data)" 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="data['show']"></app-district>
</tbody>
**componentA.ts**
OngetState(state) {
this.cs.getState(state)
this.cs.getDataDistrictWise(state)
// this.showDistrict=!this.showDistrict
}
showHideData(data) {
if(data && data['show'] == true) {
data['show'] = false;
} else {
data['show'] = true;
}
}

TA貢獻1834條經驗 獲得超8個贊
我希望你可以從你提到的參考資料中嘗試一些東西
<tr>
<td (click)="OngetState(data.state,i)" style="font-weight: 600;">{{data.state}}</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<app-district *ngIf="selectedIndex == i && showDistrict==true"></app-district>
組件.ts
selectedIndex = -1;
showDistrict:boolean=false
OngetState(state,i) {
console.log(this.showDistrict)
this.cs.getState(state)
this.cs.getDataDistrictWise(state)
this.selectedIndex = i;
this.showDistrict=!this.showDistrict
console.log(this.showDistrict)
}
添加回答
舉報