ng-style in angularjs dynamically changes the style in js

Definition and Usage

The ng-style directive adds a style attribute to HTML elements.

The value of the ng-style attribute must be an object, and the expression returned is also an object

 

example

<body ng-app="myApp" ng-controller="myCtrl">

<h1 ng-style="myObj">stupider你好!</h1>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.myObj =

   {
        "color" : "white",
        "background-color" : "coral",
        "font-size" : "60px",
        "padding" : "50px"
    }
});
</script>
</body>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326986650&siteId=291194637
Recommended