为什么不让NgClass成为Css?

时间:2018-04-23 09:29:06

标签: css angular

我有一个问题,我正在使用Angular2,我想要使用不同的样式和ngClass切换索引' NgFor'但我什么也得不到......

抱歉我的英文。

  

<div class='line'></div>
<clr-icon *ngFor="let step of steps; let i = index" shape="circle" 
class='circle' attr.ng-class="circle{{ i + 1 }}"
size="36">
</clr-icon>
<clr-icon *ngIf="steps.length == 1" attr.ng-class="circle{{ 2 }}" shape="circle" class='circle' size="36"></clr-icon>

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.mycontainer {
  position: relative;
  width: 100%;
  display: block;
}

.step {
  position: absolute;
  left: 0%;
  width: 100%;

  .circle {
    color: black;
    margin-top: -30px;
    background-color: white;
  }

  .circle1 {
    position: absolute;
    left: 0%;
  }
  .circle2 {
    position: absolute;
    right: 0%;
    background-color: black;
    color: yellow;
    /*@calcularposicion();*/
  }
}

.line {
  height: 5px;
  width: 100%;
  background-color: green;
}

在我的第二个圈子中,我会看到颜色&#39;黄色&#39;但我什么也看不见。 如果我检查Html,我有班级=&#39;圈&#39;和class =&#39; circle2&#39;

1 个答案:

答案 0 :(得分:2)

attr.ng-class更改为[ngClass]。 NgClass不是属性。这是Angular提供的指令。

<clr-icon *ngFor="let step of steps; let i = index" [ngClass]="'circle' + (i + 1)"></clr-icon>


<clr-icon *ngIf="steps.length == 1" [ngClass]="'circle2'"></clr-icon>
相关问题