Bỏ qua đến nội dung
Bỏ qua điều hướng
MT MT.Net.VNDigital Platform
Đăng nhập
MT.NET.VN

MT.Net.VN

Tìm kiếm
MT LEARNING · LESSON

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

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

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

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ử »

Zalo Messenger Gọi điện Hỗ trợ0
Home Dịch vụ Khóa học CPanel