如何在ng-repeat遍历的元素中动态设置样式
展开全部
<html ng-app="myApp">
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="js/angular.js"></script>
</head>
<body ng-controller="myCtrl">
<input type="checkbox" ng-model="isAgreen"/>同意?
<script>
var app=angular.module('myApp',['ng']);
app.controller("myCtrl",function($scope){
$scope.$watch("isAgreen",function(){
console.log($scope.isAgreen);
});
});
</script>
</body>
</html>
<img src="http://img.blog.csdn.net/20161103195723492?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
</span>
这段代码是在没数据的时候可以直接在控制台打印出true或false。
[html] view plain copy
<span style="color:#006600;"><!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="js/angular.js"></script>
</head>
<body ng-controller="myCtrl">
<table>
<thead>
<tr>
<th>请选择</th>
<th>姓名</th>
<th>生日</th>
</tr>
</thead>
<tbody>
<span style="color:#FF0000;"><tr ng-repeat="obj in data">
<td><input type="checkbox" ng-model="isAgreen" />同意?</td></span>
<td>{{obj.name}}</td>
<td>{{obj.age}}</td>
<td>{{$index}}</td>
</tr>
</tbody>
</table>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="js/angular.js"></script>
</head>
<body ng-controller="myCtrl">
<input type="checkbox" ng-model="isAgreen"/>同意?
<script>
var app=angular.module('myApp',['ng']);
app.controller("myCtrl",function($scope){
$scope.$watch("isAgreen",function(){
console.log($scope.isAgreen);
});
});
</script>
</body>
</html>
<img src="http://img.blog.csdn.net/20161103195723492?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
</span>
这段代码是在没数据的时候可以直接在控制台打印出true或false。
[html] view plain copy
<span style="color:#006600;"><!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="js/angular.js"></script>
</head>
<body ng-controller="myCtrl">
<table>
<thead>
<tr>
<th>请选择</th>
<th>姓名</th>
<th>生日</th>
</tr>
</thead>
<tbody>
<span style="color:#FF0000;"><tr ng-repeat="obj in data">
<td><input type="checkbox" ng-model="isAgreen" />同意?</td></span>
<td>{{obj.name}}</td>
<td>{{obj.age}}</td>
<td>{{$index}}</td>
</tr>
</tbody>
</table>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询