Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

AngularJS ng-style Directive

AngularJS ng-style Instruction

AngularJS Reference Manual AngularJS Reference Manual


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

<

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

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

<

/element

All 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 AngularJS Reference Manual