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

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

ngIf 中的條件如何僅對所選行為真

ngIf 中的條件如何僅對所選行為真

UYOU 2021-06-28 00:20:23
我正在使用 Angular 版本 7 開發一個 angular 項目。我有一個顯示一些 json 對象的表。在每個 json 對象中,我添加了 2 個按鈕,當每個按鈕被選中時,我都會有條件地顯示這些按鈕。我的意思是,當我單擊“編輯”按鈕時,我希望僅在我按下按鈕的那一行顯示“無編輯”按鈕,反之亦然。但是發生的情況是,當我單擊特定行的“編輯”按鈕時,其他行的所有其他按鈕都會更改。我怎樣才能做到這一點?myapp.component.html文件:<table>    <thead>      <tr>        <th scope="col" translate>Name</th>        <th scope="col" translate>Description</th>      </tr>    </thead>    <tbody>      <tr *ngFor=" let product of products">        <td>{{product.name}}</td>        <td>{{datasource.description}}</td>        <td>          <button *ngIf="allowEdit" (click)="edit(product)">            Edit          </button>&nbsp;          <button *ngIf="allowNoEdit" (click)="noEdit(product)">            No Edit          </button>&nbsp;        </td>      </tr>    </tbody>  </table>myapp.component.ts文件:allowEdit: boolean = true;allowNoEdit: boolean = false;edit(product) {   this.allowEdit= !this.allowEdit;   this.allowNoEdit= !this.allowNoEdit;}noEdit(product) {   this.allowEdit= !this.allowEdit;   this.allowNoEdit= !this.allowNoEdit;}
查看完整描述

3 回答

?
慕田峪4524236

TA貢獻1875條經驗 獲得超5個贊

包含將此類按鈕顯示為 json 對象的一部分的條件怎么樣?單擊編輯時,您可以修改特定 json 對象(行)的標志并顯示您需要的任何內容

為每個產品初始化 a product.allowEdit = false。然后你的Edit按鈕會調用一個allowEdit(product)()函數,你可以在其中更改標志product.allowEdit = !product.allowEdit;


查看完整回答
反對 回復 2021-07-01
  • 3 回答
  • 0 關注
  • 142 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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