angular整理

angular.js 学习

定义class的三种方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<html ng-app='myApp'>
<head>
<style>
.red{color: red;}.red2{color: #f0f;}
.red3{color: #00f;}.red4{color: #2ff;}
</style>
</head>
<body ng-controller="myCtrl">
<p ng-class="{{red}}">111</p>
<p ng-class="{true: 'red', false: 'red2'}[isActive]">222</p>
<p ng-class="{'red3': isSelected, 'red4': isCar}">444</p>
<script src="node_modules\angular\angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.red="red";
$scope.isActive = false;
$scope.isSelected = true;
$scope.isCar = false;
});
</script>
</body>
</html>
坚持原创技术分享,您的支持将鼓励我继续创作!