AngularJS ng-repeatညွှန်ကြားချက်


ဥပမာ

records array တွင် အကြောင်းအရာတစ်ခုစီအတွက် ခေါင်းစီးတစ်ခုရေးပါ-

<body ng-app="myApp" ng-controller="myCtrl">

<h1 ng-repeat="x in records">{{x}}</h1>

<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.records = [
        "Alfreds Futterkiste",
        "Berglunds snabbköp",
        "Centro comercial Moctezuma",
        "Ernst Handel",
    ]
});
</script>

</body>

အဓိပ္ပါယ်နှင့် အသုံးပြုမှု

ng-repeatလမ်းညွှန်ချက်သည် ပေးထားသော အကြိမ်အရေအတွက်အတိုင်း HTML အစုအဝေးတစ်ခုကို ပြန်လုပ်သည်

စုစည်းမှုတစ်ခုရှိ အကြောင်းအရာတစ်ခုလျှင် HTML အစုံကို ထပ်ခါတလဲလဲ ပြုလုပ်ပါမည်။

စုစည်းမှုသည် array သို့မဟုတ် အရာဝတ္ထုတစ်ခု ဖြစ်ရမည်။

မှတ်ချက်- ထပ်ခါတလဲလဲမှု၏ စံနမူနာတစ်ခုစီကို လက်ရှိအရာပါ၀င်သည့် ၎င်း၏ကိုယ်ပိုင်နယ်ပယ်ကို ပေးထားသည်။

သင့်တွင် အရာဝတ္ထုများ အစုအဝေးတစ်ခုရှိပါက၊ ng-repeatညွှန်ကြားချက်သည် HTML ဇယားတစ်ခုပြုလုပ်ရန်၊ အရာတစ်ခုစီအတွက် ဇယားတစ်ခုစီအတွက် ဇယားတစ်ခုစီနှင့် အရာဝတ္ထုပစ္စည်းပိုင်ဆိုင်မှုတစ်ခုစီအတွက် ဇယားတစ်ခုစီဒေတာအတွက် ပြီးပြည့်စုံသည်။ အောက်ပါဥပမာကိုကြည့်ပါ။


အထားအသို

<element ng-repeat="expression"></element>

HTML ဒြပ်စင်များအားလုံးမှပံ့ပိုးထားသည်။


ကန့်သတ်တန်ဖိုးများ

Value Description
expression An expression that specifies how to loop the collection.

Legal Expression examples:

x in records

(key, value) in myObj

x in records track by $id(x)


နောက်ထပ် ဥပမာများ

ဥပမာ

records array ရှိ အကြောင်းအရာတစ်ခုစီအတွက် ဇယားတစ်ခုစီကို ရေးပါ-

<table ng-controller="myCtrl" border="1">
    <tr ng-repeat="x in records">
        <td>{{x.Name}}</td>
        <td>{{x.Country}}</td>
    </tr>
</table>

<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.records = [
       {
            "Name" : "Alfreds Futterkiste",
            "Country" : "Germany"
        },{
            "Name" : "Berglunds snabbköp",
            "Country" : "Sweden"
        },{
            "Name" : "Centro comercial Moctezuma",
            "Country" : "Mexico"
        },{
            "Name" : "Ernst Handel",
            "Country" : "Austria"
        }
    ]
});
</script>

ဥပမာ

အရာဝတ္ထုတစ်ခုရှိ ပစ္စည်းတစ်ခုစီအတွက် ဇယားတစ်တန်းကို ရေးပါ-

<table ng-controller="myCtrl" border="1">
    <tr ng-repeat="(x, y) in myObj">
        <td>{{x}}</td>
        <td>{{y}}</td>
    </tr>
</table>

<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.myObj = {
        "Name" : "Alfreds Futterkiste",
        "Country" : "Germany",
        "City" : "Berlin"
    }
});
</script>