【问题标题】:Angular Changing Row Color when Preview Button is Clicked单击预览按钮时角度更改行颜色
【发布时间】:2022-01-03 14:42:10
【问题描述】:

在我的代码中,我为用户可以预览项目的每一行提供了一个表格和一个按钮。由于表格包含很多元素,所以当点击预览按钮时,我希望行颜色变为黄色。现在,我无法以我尝试的方式成功。我应该怎么做才能达到我想要的?

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();
            });
    }

【问题讨论】:

    标签: javascript html angular typescript


    【解决方案1】:

    尝试为名为 isYellow 的行对象添加额外的属性。如果有未定义或假值类黄色将不显示。 HTML:

    <button mat-icon-button class="sidebar-toggle" (click)="preview(row)" [ngClass]="{'yellow' : row.isYellow}">
    <mat-icon>pageview</mat-icon>
    </button>
    

    Ts:

     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();
                });
        }
    

    【讨论】:

    • 好的,谢谢,这有点奏效。因为现在,只有按钮变成黄色,而不是行。 ://
    • 您可以将班级位置更改为行标签。
    • 好的,现在可以了。我还有一个问题。当我点击另一行时,我应该怎么做才能从一行中删除黄色?
    • foreach 循环将所有 isYellow 值更改为 false,然后再为单击的值分配 true 值。
    猜你喜欢
    • 1970-01-01
    • 2021-12-12
    • 2020-01-21
    • 2019-03-28
    • 1970-01-01
    • 2021-12-21
    • 2021-07-07
    • 2012-12-06
    • 2016-09-08
    相关资源
    最近更新 更多