1 ng-repeat指令: 循环输出数组或者对象内容到html
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>apply watch</title>
<link rel="stylesheet" type="text/css" href="css/lib/bootstrap.css">
<script src="js/lib/angular.min.js"></script>
<style type="text/css">
*{margin: 0;padding: 0;}
</style>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div class="container-fluid">
<table class="table table-striped">
<thead>
<tr>
<th>姓名</th>
<th>介绍</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in list">
<td>{{item.name}}</td>
<td>{{item.content}}</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
var app = angular.module("myApp",[]);
app.controller('myCtrl', function($scope) {
$scope.list = [
{name: "慕容复",content: "金庸武侠悲剧人物,曾与主角乔峰大战百余回合而未落败。"},
{name: "张无忌",content: "金庸武侠一代传奇高手,擅长九阳神功以及乾坤大挪移。"},
{name: "慕容复",content: "金庸武侠悲剧人物,曾与主角乔峰大战百余回合而未落败。"},
{name: "张无忌",content: "金庸武侠一代传奇高手,擅长九阳神功以及乾坤大挪移。"},
];
});
</script>
</body>
</html>
页面: 一条数据占一行,如果分行显示则不容易实现。
2 ng-repeat-start ng-repeat-end指令: 将数组或对象的一条数据分行显示。
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>apply watch</title>
<link rel="stylesheet" type="text/css" href="css/lib/bootstrap.css">
<script src="js/lib/angular.min.js"></script>
<style type="text/css">
*{margin: 0;padding: 0;}
</style>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div class="container-fluid">
<table class="table table-striped">
<tbody>
<tr ng-repeat-start="item in list">
<td>姓名</td>
<td>{{item.name}}</td>
</tr>
<tr ng-repeat-end>
<td></td>
<td>{{item.content}}</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
var app = angular.module("myApp",[]);
app.controller('myCtrl', function($scope) {
$scope.list = [
{name: "慕容复",content: "金庸武侠悲剧人物,曾与主角乔峰大战百余回合而未落败。"},
{name: "张无忌",content: "金庸武侠一代传奇高手,擅长九阳神功以及乾坤大挪移。"},
{name: "慕容复",content: "金庸武侠悲剧人物,曾与主角乔峰大战百余回合而未落败。"},
{name: "张无忌",content: "金庸武侠一代传奇高手,擅长九阳神功以及乾坤大挪移。"},
];
});
</script>
</body>
</html>
页面:实现分行显示一条数据。