【问题标题】:How to add style property to the element having ng-class dynamically in angularjs如何在angularjs中动态地将样式属性添加到具有ng-class的元素
【发布时间】:2018-07-23 13:38:12
【问题描述】:

如何传递类:使用 ng-class 后,如何向现有的 css 类添加属性 我有css作为

<style>
customcss:after{
 border-top: 7px solid green;
}
</style>

我想使用 ng-class 或 ng-style 动态改变颜色

我用过

<html>
    <div ng-class="{customcss: true}" ng-style="topcolor('yellow')"></div>
 </html>
<script>
 $scope.topcolor = function (color) {
                return '7px solid ' + color;
            }
</script>
enter code here

就像上面我用过的一样,但是颜色没有动态变化

请帮我解决这个问题。

【问题讨论】:

    标签: css angularjs ng-class


    【解决方案1】:

    在 HTML 中

    <div class="customcss" ng-style="topcolor('yellow')"></div>
    

    在控制器中:

    $scope.topcolor = function(value) {
              return { "border-top": '7px solid ' + value};
          }
    

    试试这个。

    【讨论】:

    • 我想动态添加 ::after 类,至少我想更新'border-top'的现有属性
    • @chaitanyak,实际上也是如此。动态更新border-top 属性。你检查了吗?
    • 我试过了,不行,我需要怎么用 -- style="customcss:after{border-top: 7px solid green; }"
    猜你喜欢
    • 2020-06-08
    • 2017-05-16
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    相关资源
    最近更新 更多