AngularJS tut 12: Bảng ( tables) 0 (0)

AngularJS tut 12: Bảng ( tables) 0 (0)

AngularJS tut 12: Bảng ( tables) 0 (0)

Learn more »

Lệnh ng-repeat hoàn hảo để hiển thị các bảng.


Hiển thị dữ liệu trong bảng

Hiển thị bảng với góc rất đơn giản:

Ví dụ về AngularJS

<div ng-app="myApp" ng-controller="customersCtrl">  <table>   <tr ng-repeat="x in names">     <td>{{ x.Name }}</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> 

Hãy tự mình thử »


Hiển thị với Kiểu CSS

Để làm cho nó đẹp, hãy thêm một số CSS vào trang:

Kiểu 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> 

Hãy tự mình thử »



Hiển thị với thứ tự

Để sắp xếp bảng, hãy thêm một trật tự bằng bộ lọc: 

Ví dụ về AngularJS

<table>
  <tr ng-repeat="x in names | orderBy : 'Country'">
    <td>{{ x.Name }}</td>
    <td>{{ x.Country }}</td>
  </tr>
</table>

Hãy tự mình thử »


Hiển thị với Bộ lọc chữ hoa

Để hiển thị chữ hoa, hãy thêm bộ lọc chữ hoa : 

Ví dụ về AngularJS

<table>
  <tr ng-repeat="x in names">
    <td>{{ x.Name }}</td>
    <td>{{ x.Country | uppercase }}</td>
  </tr>
</table>

Hãy tự mình thử »


Hiển thị table index ($index)

Để hiển thị chỉ mục bảng, hãy thêm một <td> với $index : 

Ví dụ về AngularJS

<table>
  <tr ng-repeat="x in names">
    <td>{{ $index + 1 }}</td>
    <td>{{ x.Name }}</td>
    <td>{{ x.Country }}</td>
  </tr>
</table>

Hãy tự mình thử »


Sử dụng $even và $odd

Ví dụ về 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>

Hãy tự mình thử »


Lượt xem : 239

Integrations
Users

Share Profile

Anyone at KeenThemes can view
Anyone with link can edit

Give Award

Anyone at KeenThemes can view
Anyone with link can edit

Report User

Let us know why you’re reporing this person
Don't worry, your report is completely anonymous; the person you're
reporting will not be informed that you've submitted it