Tabele AngularJS
- Poprzednia strona Http AngularJS
- Następna strona Wybór AngularJS
instrukcja ng-repeat jest bardzo odpowiednia do wyświetlania tabel.
Wyświetlanie danych w tabeli
Wyświetlanie tabeli za pomocą AngularJS jest bardzo proste:
Przykłady AngularJS
<div ng-app="myApp" ng-controller="customersCtrl"> <table> <tr ng-repeat="x in names"> <td>{{ x.Nazwa }}</td> <td>{{ x.Country }}</td> </tr> </table> </div> <script> var app = angular.module('myApp', []); app.controller('customersCtrl', function($scope, $http) { $http.get("customers.php") .then(function (response) {$scope.names = response.data.records;}); }); </script>
Wyświetl za pomocą stylów CSS
Aby uczynić to bardziej ładnym, możesz dodać trochę CSS do strony:
Styl 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>
Wyświetl za pomocą filtru sortujPo
Aby posortować tabelę, dodaj sortujPo
Filtr:
Przykład AngularJS
<table> <tr ng-repeat="x in names | sortujPo : 'Kraj'"> <td>{{ x.Nazwa }}</td> <td>{{ x.Country }}</td> </tr> </table>
Wyświetl w formie wielkiej litery za pomocą filtru wielkieLitery
Aby wyświetlić w formie wielkiej litery, dodaj wielkieLitery
Filtr:
Przykład AngularJS
<table> <tr ng-repeat="x in names"> <td>{{ x.Nazwa }}</td> <td>{{ x.Kraj | wielkieLitery }}</td> </tr> </table>
Wyświetl indeks tabeli ($index)
Aby wyświetlić indeks tabeli, dodaj $index
w <td>:
Przykład AngularJS
<table> <tr ng-repeat="x in names"> <td>{{ $index + 1 }}</td> <td>{{ x.Nazwa }}</td> <td>{{ x.Country }}</td> </tr> </table>
Użycie $even i $odd
Przykład AngularJS
<table> <tr ng-repeat="x in names"> <td ng-if="$odd" style="background-color:#f1f1f1">{{ x.Name }}</td> <td ng-if="$even">{{ x.Name }}</td> <td ng-if="$odd" style="background-color:#f1f1f1">{{ x.Country }}</td> <td ng-if="$even">{{ x.Country }}</td> </tr> </table>
- Poprzednia strona Http AngularJS
- Następna strona Wybór AngularJS