AngularJS ဇယားများ


ng-repeat ညွှန်ကြားချက်သည် ဇယားများကိုပြသရန်အတွက် ပြီးပြည့်စုံသည်။


ဇယားတစ်ခုတွင် Data ကိုပြသခြင်း။

ဇယားများကို ထောင့်မှန်ဖြင့်ပြသခြင်းသည် အလွန်ရိုးရှင်းပါသည်။

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 Style ဖြင့်ပြသခြင်း။

၎င်းကို ကောင်းမွန်စေရန်၊ စာမျက်နှာသို့ 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>


အမှာစာBy Filter ဖြင့်ပြသပါ။

ဇယားကိုစီရန်၊ အမှာ စာအလိုက် စစ်ထုတ်မှုတစ်ခု ထည့်ပါ- 

AngularJS ဥပမာ

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

စာလုံးကြီး Filter ဖြင့်ပြသပါ။

စာလုံးကြီးပြရန်၊ စာလုံးကြီး စစ်ထုတ်မှုကို ထည့်ပါ- 

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>