在我的代碼中,我為每一行都有一個表格和一個按鈕,用戶可以在其中預覽專案。由于表格包含很多元素,當點擊預覽按鈕時,我希望行顏色變為黃色。現在,以我嘗試的方式,我無法成功。我該怎么做才能實作我想要的?

HTML:
<button mat-icon-button class="sidebar-toggle" (click)="preview(row)" [ngClass]="{'yellow' : EditIndex == i}">
<mat-icon>pageview</mat-icon>
</button>
TS:
preview(labPeriod: ILabPeriod) {
this.labPeriodPreview = undefined;
this._labService
.getLabAnalysisTestResultsList(labPeriod.LabPeriodId)
.subscribe((response: ILabConditionResult[]) => {
this.labAnalysis.LabConditionResults = response;
labPeriod.LabAnalysis = this.labAnalysis;
this.labPeriodPreview = labPeriod;
this._fuseSidebarService
.getSidebar("analysis-detail-period-preview")
.open();
});
}
uj5u.com熱心網友回復:
嘗試向名為 isYellow 的行物件添加額外的屬性。如果有未定義或假值類黃色將不會顯示。HTML:
<button mat-icon-button class="sidebar-toggle" (click)="preview(row)" [ngClass]="{'yellow' : row.isYellow}">
<mat-icon>pageview</mat-icon>
</button>
:
preview(labPeriod: ILabPeriod) {
//new
//todo loop through all rows and set isYellow to false
labPeriod.isYellow = true;
//new
this.labPeriodPreview = undefined;
this._labService
.getLabAnalysisTestResultsList(labPeriod.LabPeriodId)
.subscribe((response: ILabConditionResult[]) => {
this.labAnalysis.LabConditionResults = response;
labPeriod.LabAnalysis = this.labAnalysis;
this.labPeriodPreview = labPeriod;
this._fuseSidebarService
.getSidebar("analysis-detail-period-preview")
.open();
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/365771.html
標籤:javascript html 有角的 打字稿
