AngularJS: ng-style or style
HTML
<body ng-app="myApp">
<div ng-controller="myCtrl">
<div class="boxClass" style="background: red"> style attribute</div>
<br>
<div class="boxClass" ng-style="getStyle(colorBg)"> set using ng style</div>
<br>
<button ng-click="changeColour()">Click Me</button>
</div>
</body>
CSS
.boxClass {
width:200px;
height:200px;
}
JavaScript
// declare a module
var myApp = this.angular.module('myApp', []);
// declare a controller
myApp.controller('myCtrl', function ($scope, $interval) {
$scope.colorBg = "F0F000";
$scope.getStyle = function(colour) {
return {"background": "#" + colour};
}
$scope.changeColour = function() {
$scope.colorBg = "FFFFFF"
}
});