AngularJS ng-style Directive
Definition and Usage
ng-style
The directive specifies the style
property.
ng-style
The value of the property must be an object or an expression that returns an object.
The object is composed of CSS properties and values in key-value pairs.
Example
Use an object with CSS keys and values to add some styles via AngularJS:
<body ng-app="myApp" ng-controller="myCtrl"> <h1 ng-style="myObj">Welcome</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>
Syntax
<element ng-style="expression</element>
All HTML elements support it.
Parameters
Parameters | Description |
---|---|
expression | The expression returns an object where the keys are CSS properties and the values are CSS values. |