【问题标题】:AngularJS ng-class and ng-style working togetherAngularJS ng-class 和 ng-style 一起工作
【发布时间】:2016-08-26 11:13:56
【问题描述】:

我的 div 中有一个 ng-repeat:

<div ng-repeat="el in list">
    <button 
     ng-class="{ 'selected' : selectedButton == $index }" 
     ng-style="{ 'background-color' : userColor }"
     >
       {{el}}
    </button>
</div>

在css文件中:

.selected{
   background-color: red;
}

想法是将背景颜色设置为红色到最后按下的按钮。并且所有其他按钮应具有先前已选择用户的背景颜色。

问题是,当 ng-style 中的背景颜色已经应用时,它不会用选定的类背景颜色覆盖它。我必须使用 selectedButton == $index ,因为其他东西都依赖于它。

有什么想法吗?谢谢!

【问题讨论】:

    标签: javascript css angularjs


    【解决方案1】:

    尝试在您的课程中使用 !important。这可能会解决您的问题。

    .selected{
       background-color: red !important;
    }
    

    在应用 !important 之前,内联样式的优先级高于类中的 css。

    来自CheezyCode的干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-11
      • 2016-07-10
      • 2019-06-24
      • 1970-01-01
      • 2016-02-06
      • 2015-12-12
      • 1970-01-01
      相关资源
      最近更新 更多