WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

AngularJS ng-style Directive


Example

Add som style with AngularJS, utilizing an item with CSS keys and values:

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

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

<script>
var application = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.myObj = {
        "color" : "white",
        "background-color" : "coral",
        "font-size" : "60px",
        "padding" : "50px"
    }
});
</script>
</body>
Try it yourself »

Definition and Usage

The ng-style mandate indicates the style property for the HTML element.

The estimation of the ng-style characteristic must be an item, or an articulation restoring an object.

The object comprises of CSS properties and qualities, in key esteem pairs.


Syntax

<element ng-style="expression"></element>

Supported by all HTML elements.


Parameter Values

Value Description
expression An articulation which restores an article where the keys are CSS properties, furthermore, the qualities are CSS values.