AngularJS ng-style Instruction
AngularJS Examples
Use AngularJS to add styles, using the CSS key=>value object format:
<
body
ng-app=
"myApp"
ng-controller=
"myCtrl"
<
h1
ng-style=
"myObj"Runoob Tutorial
<
/h1
<
scriptvar app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.myObj = {
"color" : "white",
"background-color" : "coral",
"font-size" : "60px",
"padding" : "50px"
}
});
<
/script
<
/bodyTry it »
Definition and Usage
ng-style The directive adds a style attribute to an HTML element.
ng-style The attribute value must be an object, and the expression returns an object as well.
The object consists of CSS properties and values, i.e., key=>value pairs.
Syntax
<
element
ng-style=
"expression"
<
/elementAll HTML elements support this attribute.
Parameter value
| Value | Description |
|---|---|
| string | An expression that returns an object consisting of CSS properties and values. |
AngularJS Reference Manual