HLJ 发布于
2018-08-16 16:47:01

AngularJS ng-style设置动态样式值

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>
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2018-08-16/105.html
最后生成于 2024-05-27 22:53:00
此内容有帮助 ?
0