首页 > 解决方案 > angular 6 用条件覆盖 css

问题描述

ng-select在我的项目中使用过,我使用 删除了交叉清除图标,并且我还通过覆盖类[clearable]="false"删除了每个项目的清除图标ng-value-icon

:host ::ng-deep .ng-value-icon {
    display: none !important;
}

我想用条件应用css

  constructor() {
    if(this.result === "ok") {
      //apply the css
    }
  }

堆栈闪电战

标签: angularangular-ngselect

解决方案


模板的这一部分(来自您的 Stackblitz)决定类custom与名为的作用域变量有关step

   [class.custom]="step === 'step1'"

所以,使用它:

  step: 'step1'|'not-step1' = 'not-step1';

  constructor() {
    if(this.result === "ok") {
      this.step = "step1";
    }
  }

或者您将模板中的条件更改为

   [class.custom]='result === "ok"'

或者,很可能比这个 css-toggle 更好,你可以使用*ngIf

  *ngIf="result === 'ok'"

.


推荐阅读