【问题标题】:Style elements if satisfy condition, AngularJS如果满足条件,则样式元素,AngularJS
【发布时间】:2015-11-03 22:09:24
【问题描述】:
<div ng-if="item.attribute == 'attribute1'">
    doSomething
</div>

<button class="button button-block button-postive waves-effect waves-button waves-light">
    Button 1
</button>

我想这样如果 item.attribute == attribute1 那么按钮的颜色是珊瑚色

.button.button-block, .button.button-full {

    background-color: coral;
    color: #fff;
}

这可能吗?谢谢

【问题讨论】:

    标签: css angularjs ng-style


    【解决方案1】:

    这是另一种不声明类的方法。

    ng-style="item.attribute == 'attribute1' 
        && {'background-color':'red', 'color':'white'} || {'background-color':'blue', 'color':'white'}"
    

    【讨论】:

      【解决方案2】:

      您可以使用ng-class 来完成此操作。

      <button ng-class="{'button-block': item.attribute==attribute1}">
      

      【讨论】:

        【解决方案3】:

        使用 ng-class

        ng-class="{ 'style': condition, 'style2' : condition2}"
        

        具体来说:

        ng-class="{ 'button-block': item.attribute == 'attribute1'}"
        

        https://docs.angularjs.org/api/ng/directive/ngClass

        【讨论】:

          猜你喜欢
          • 2013-11-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-07-13
          • 1970-01-01
          相关资源
          最近更新 更多