【问题标题】:how to add a red dot on a mat step header icon in angular 7?如何在角度 7 中的垫子步骤标题图标上添加红点?
【发布时间】:2019-12-31 13:44:54
【问题描述】:

仅当该垫子步骤的表单字段中有任何错误时,我才想在有角材料步进器头图标上添加一个红点。为此,我尝试在步进器类中添加 div ,但它没有生效。至少我想知道如何使用类动态添加 div。

<mat-step-header class="mat-horizontal-stepper-header mat-step-header ng-tns-c10-1 ng-star-inserted" role="tab"
    ng-reflect-state="number" ng-reflect-label="Basic Information" ng-reflect-icon-overrides="[object Object]"
    ng-reflect-index="0" ng-reflect-selected="true" ng-reflect-active="true" ng-reflect-optional="false" tabindex="0"
    id="cdk-step-label-0-0" aria-posinset="1" aria-setsize="2" aria-controls="cdk-step-content-0-0"
    aria-selected="true">
    <div class="mat-step-header-ripple mat-ripple" mat-ripple="" ng-reflect-trigger="[object HTMLElement]"></div>
    <div class="mat-step-icon-state-number mat-step-icon mat-step-icon-selected">
        <div class="mat-step-icon-content" ng-reflect-ng-switch="false">
            <span class="ng-star-inserted">1</span>
        </div>
    </div>
    <div class="mat-step-label mat-step-label-active mat-step-label-selected">
        <div class="mat-step-text-label ng-star-inserted">Basic Information</div>
    </div>
</mat-step-header>

【问题讨论】:

标签: angular typescript angular-material


【解决方案1】:

您可以使用formgroup.valid 属性,该属性根据表单有效性返回一个布尔值,并且在 ngClass 的帮助下您可以设置成功或错误类别。

相关 HTML:

<ng-template matStepLabel>
  <div [ngClass]="firstFormGroup.valid ? 'suc' : 'err'">
    {{firstFormGroup.valid}}
  </div>
</ng-template>

CSS:

.err {
  background-color: red;
}

.suc {
  background-color: green;
}

Here is a working Demo

【讨论】:

    猜你喜欢
    • 2018-07-09
    • 1970-01-01
    • 2020-08-03
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    相关资源
    最近更新 更多