經過controller.js中的某個$scope變量的值來決定div標籤(或者其餘html標籤)的樣式表。html
使用ng-style指令在div標籤上angularjs
<body ng-app="myApp" ng-controller="myCtrl"> <div ng-style="myStyle">菜鳥教程</div> <script> var app = angular.module("myApp", []); app.controller("myCtrl", function($scope) { $scope.myStyle = { "color" : "white", "background-color" : "coral", "font-size" : "60px", "padding" : "50px" } }); </script> </body>
@完app