ng-style和自定义CSS属性

3

是否可以在ng-style中添加自定义的CSS属性,例如CSS变量?

我尝试使用以下方法:

<li ng-repeat="item in vm.items" ng-style="{'--index': $index}">{{item.name}}</li>

但是这并不起作用,当我在开发者工具中检查时,在样式属性中没有`--index`。
2个回答

1

不,你必须输入有效的CSS属性,如

<li ng-repeat="item in vm.items" ng-style="{'z-index': $index}">{{item.name}}</li>

0
尝试这种方式:
<body ng-app="myApp" ng-controller="myCtrl">

<h1 ng-style="myObj">Welcome</h1>


<script>
//u can put that <script> content in a separadet file
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.myObj = {
        "color" : "white",
        "background-color" : "coral",
        "font-size" : "60px",
        "padding" : "50px"
    }
});
</script>
</body>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接