在我的Angular項目中,我有它,所以在grid component
有ngSwitch
,如果沒有選擇行,默認選項是row display component
,您可以查看數據顯示如果選擇了一行,則切換到row edit component
,您可以在其中編輯數據。我還在row edit component
中實施了一個接受按鈕,以便在您完成更改時保存更改。我無法找到如何做的是在已更新的行更新後,恢復爲row display component
。我會怎麼做呢?如何切換功能內部組件
下面是該ngSwitch
在我grid component
代碼:
<ng-container *ngFor="let pto of (ptoData | currentEmployee:empInfo[selectedEmployee].EmpKey); let i = index">
<ng-container [ngSwitch]="isRowSelected(i)">
<ng-container *ngSwitchCase="false">
<ng-container *ngIf="pto.type === selectedType">
<tr pto-row-display [pto]="pto" (click)="selectRow(i)"></tr>
</ng-container>
</ng-container>
<ng-container *ngSwitchCase="true">
<tr pto-row-edit [pto]="pto" (onDelete)="onDelete($event)" *ngIf="pto.type === selectedType"></tr>
</ng-container>
</ng-container>
</ng-container>
,然後這裏是在row edit component
我保存/更新功能:
saveRow(p : PTOData): void {
this.ptodataService.update(p)
}
這裏是我的rowSelected代碼:
rowSelected: number;
isRowSelected(i: number) {
return i == this.rowSelected;
}
selectRow(i: number) {
this.rowSelected = i;
}
你能最少顯示你的ngSwitch代碼嗎? – Zircon
@Zircon更新了原始帖子 – asdf