【问题标题】:how to change style *ngFor (loop) angular 2如何更改样式 *ngFor(循环)角度 2
【发布时间】:2017-08-27 06:46:48
【问题描述】:

我用 *ngFor 制作了一组复选框,如果我单击它们中的每一个,我希望它们的颜色会发生变化,如果再次单击,颜色会返回到以前的颜色:

<div *ngFor="let chekb of amenities" class="checkbox col-md-4 nopadding">
<label>
  <input class="removebox" type="checkbox" (change)="changecheckbox($event)" name="checked" [(ngModel)]="chekb.checked">
  {{chekb.title}}
</label>
</div>

组件:

public amenities: checkBoxClass[] = [
{title:"pool",value:"pool" ,checked:false},
{title:"parking",value:"parking", checked:false}
]

实际上是一个复选框,可以选择其中任何一个或两个或多个。 如何通过单击它们来更改它们的颜色? 非常感谢。

【问题讨论】:

  • 您需要在颜色之间切换还是随机任意数量的颜色?
  • 签出很棒的引导复选框...

标签: css angular


【解决方案1】:
@component({
  ...
  ...

 /****** added style  ******/
  style:[
    `
       mycolor:{background : red}              
    `
  ]

})    


<div *ngFor="let chekb of amenities;let i=index"           //modified
      class="checkbox col-md-4 nopadding">
          <label [class.mycolor]="chekb.checked">          //modified
              <input class="removebox" 
                     type="checkbox" 
                     (change)="changecheckbox($event)" 
                     name="checked" 
                     [(ngModel)]="chekb.checked">

                             {{chekb.title}}

            </label>
</div>

【讨论】:

    猜你喜欢
    • 2020-11-23
    • 1970-01-01
    • 2016-12-03
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多