AngularJS ng-style设置动态样式值
html代码:
<body ng-app="myApp" ng-controller="myCtrl">
<h1 ng-style="myObj">angular</h1>
<h1 ng-style="setBg(color)">angular</h1>
<h1 ng-style="{'background-color' :'{{color}}'}">angular</h1>
</body>
JavaScript代码:
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.myObj = {
"color" : "white",
"background-color" : "coral",
"font-size" : "60px",
"padding" : "50px"
}
$scope.color="coral"
$scope.setBg = function(color) {
return { 'background': color };
};
});
</script>