我正在使用 Angular 版本 7 開發(fā)一個(gè) angular 項(xiàng)目。我有一個(gè)顯示一些 json 對(duì)象的表。在每個(gè) json 對(duì)象中,我添加了 2 個(gè)按鈕,當(dāng)每個(gè)按鈕被選中時(shí),我都會(huì)有條件地顯示這些按鈕。我的意思是,當(dāng)我單擊“編輯”按鈕時(shí),我希望僅在我按下按鈕的那一行顯示“無(wú)編輯”按鈕,反之亦然。但是發(fā)生的情況是,當(dāng)我單擊特定行的“編輯”按鈕時(shí),其他行的所有其他按鈕都會(huì)更改。我怎樣才能做到這一點(diǎn)?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> <button *ngIf="allowNoEdit" (click)="noEdit(product)"> No Edit </button> </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;}
ngIf 中的條件如何僅對(duì)所選行為真
UYOU
2021-06-28 00:20:23