{% raw %}
# AngularJS 表格
ng-repeat 指令可以完美的顯示表格。
## 在表格中顯示數據
使用 angular 顯示表格是非常簡單的:
## AngularJS 實例
```
<div ng-app="" ng-controller="customersController">
<table>
? <tr ng-repeat="x in names">
??? <td>{{ x.Name }}</td>
??? <td>{{ x.Country }}</td>
? </tr>
</table>
</div>
<script>
function customersController($scope,$http) {
? $http.get("http://www.w3cschool.cc/try/angularjs/data/Customers_JSON.php")
? .success(function(response) {$scope.names = response;});
}
</script>
```
## 使用 CSS 樣式
為了讓頁面更加美觀,我們可以在頁面中使用CSS:
## CSS 樣式
```
<style>
table, th , td {
? border: 1px solid grey;
? border-collapse: collapse;
? padding: 5px;
}
table tr:nth-child(odd) {
? background-color: #f1f1f1;
}
table tr:nth-child(even) {
? background-color: #ffffff;
}
</style>
```
## 排序顯示
如果需要對表格進行排序,我們可以添加 **orderBy** 過濾器:?
## AngularJS 實例
```
<table>
? <tr ng-repeat="x in names | orderBy : 'Country'">
??? <td>{{ x.Name }}</td>
??? <td>{{ x.Country }}</td>
? </tr>
</table>
```
[Try it Yourself ?](/try/try.php?filename=try_ng_tables_orderby)
## 使用 uppercase 濾器
如果字母要轉換為大寫,可以添加 **uppercase** 過濾器:?
## AngularJS 實例
```
<table>
? <tr ng-repeat="x in names">
??? <td>{{ x.Name }}</td>
??? <td>{{ x.Country | uppercase}}</td>
? </tr>
</table>
```
{% endraw %}