亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

根據Angular 9中我的表格列的標題,基于表格內特定標題的單擊事件顯示/隱藏組件

根據Angular 9中我的表格列的標題,基于表格內特定標題的單擊事件顯示/隱藏組件

慕容森 2022-06-09 19:03:16
我在 Angular 應用程序中工作,我正在開發 COVID 19 應用程序。在這里,我有 2 個組件,其中組件 A 列出了所有州,組件 B 列出了特定州的所有區?,F在我已經以表格格式顯示了組件的所有數據,當我單擊該狀態時,它應該加載單擊狀態的所有數據,當我再次單擊該狀態時,它應該關閉。此外,如果我點擊所有地區的其他州列表,該州應該會顯示出來但我不知道把我的放在哪里,<app-componentB></app-componentB>因為如果把它放在 for 循環中,如果我嘗試顯示一個州的列表,它會在所有州下顯示相同的地區列表這是我的一段代碼組件A.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>組件A.ts showDistrict=true  OngetState(state) {    this.cs.getState(state)    this.cs.getDataDistrictWise(state)    this.showDistrict=!this.showDistrict  }
查看完整描述

2 回答

?
慕的地10843

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;

    }

  }


查看完整回答
反對 回復 2022-06-09
?
MMMHUHU

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)

  }


查看完整回答
反對 回復 2022-06-09
  • 2 回答
  • 0 關注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號