AngularJS टेबल

ng-repeat निर्देशक तालिका दिखाने के लिए बहुत उपयोगी है。

तालिका में डाटा दिखाएं

AngularJS के द्वारा तालिका दिखाना बहुत सरल है:

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>

स्वयं प्रयास करें

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 फिल्टर के द्वारा दिखाएं

तालिका को क्रमबद्ध करने के लिए जोड़ें orderBy फिल्टरः

AngularJS उदाहरण

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

स्वयं प्रयास करें

uppercase फिल्टर के द्वारा दिखाएं

बड़े पैमाने पर दिखाने के लिए जोड़ें uppercase फिल्टरः

AngularJS उदाहरण

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

स्वयं प्रयास करें

तालिका संकेत ($index)

तालिका संकेत दिखाने के लिए जोड़ें $index का <td>:

AngularJS उदाहरण

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

स्वयं प्रयास करें

$even और $odd का उपयोग करना

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>

स्वयं प्रयास करें