AngularJS ng-style directive
AngularJS instance
Add styles using AngularJS, and use CSS key=>value object format:
<!DOCTYPE html><html><head><meta charset="utf-8"><script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script></head><body ng-app="myApp" ng-controller="myCtrl"><h1 ng-style="myObj">Rookie 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></html>Definition and usage
The ng-style directive adds a style attribute to an HTML element.
The ng-style attribute value must be an object, and the expression returns the object.
Objects are registered by CSS attributes and values, i.e. key=>value pairs.
grammar
<element ng-style="expression"></element>
All HTML elements support this property.
Parameter value
| value | describe |
|---|---|
| string | An expression returns an object composed of CSS attributes and values. |
The above is the information compilation of the AngularJS ng-style instruction. We will continue to add it later. Thank you for your support for this site!