AngularJS添加樣式

AngularJS添加樣式

經過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

參考:http://www.runoob.com/angularjs/ng-ng-style.htmlcode

相關文章
相關標籤/搜索