ng-style and custom css properties

1.4k views Asked by At

Is it possible to add custom css properties aka css variables inside ng-style?

I have tried to use this:

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

but this doesn't work I got no --index in style attribute when inspect in developer tools.

2

There are 2 answers

0
Ahmed Mostafa On BEST ANSWER

no you must type a valid CSS property like

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

try this way:

<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>