我有以下的HTML代碼:Angular 2:如何隱藏按鈕* ngFor的選擇性迭代?
<table>
<tr *ngFor='let product of products'>
<td>
<button [hidden]="hidebutton" (click)="Follow(product.Id)">Follow</button>
</td>
</tr>
</table>
和相應的點擊事件在我的打字稿followproduct.component.ts:
@Component({
---
---
})
export class followproduct implements onInit{
hidebutton: boolean = false;
Follow(productId: number) {
---
this.hidebutton = true;
}
}
一旦點擊一個產品的跟蹤按鈕,其他產品的所有按鈕在迭代中被隱藏 - 這也是顯而易見的,因爲我正在爲迭代按鈕標籤分配隱藏選項。
有沒有什麼辦法隱藏,更新或更改只有選擇性迭代* ngFor的按鈕?
不,這在我的代碼中不起作用。事實上,它會完全停止顯示其他迭代。 –
我編輯了示例ngFor演示以滿足您的需求。作爲我的代碼上面但我必須改變isHidden從任何到任何[]。 http://plnkr.co/edit/E00kPmnzKb7Lql4iWa26?p=preview – garethb
感謝您的編輯。我的代碼現在正在工作。 –