AngularJS NG-Repeat-Richtlinie
AngularJS -Instanz
Schleifen Sie mehrere Titel aus:
<! DocType html> <html> <head> <meta charset = "utf-8"> <script src = "http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> </script> </head> <bodyng-app-app-App = "myApp" ng-Controller = "myclll- ng-repeat="x in records">{{x}}</h1><script>var app = angular.module("myApp", []);app.controller("myCtrl", function($scope) { $scope.records = [ "Rookie Tutorial 1", "Rookie Tutorial 2", "Rookie Tutorial 3", "Rookie Tutorial 4 ",]}); </script> </body> </html>Definition und Verwendung
Die NG-Repeat-Direktive wird verwendet, um die HTML-Elemente einer bestimmten Häufigkeit herauszufinden.
Die Sammlung muss ein Array oder Objekt sein.
Grammatik
<Element ng-Repeat = "Expression"> </Element>
Alle HTML -Elemente unterstützen diese Richtlinie.
Parameterwert
| Wert | beschreiben |
|---|---|
| Ausdruck | Ausdrücke definieren, wie man eine Sammlung schaufelt. Ausdrucksinstanzregeln: x in Aufzeichnungen (Schlüssel, Wert) in myobj x In Records Track von $ id (x) |
Weitere Beispiele
AngularJS -Instanz
Verwenden Sie ein Array, um eine Tabelle herauszuholen:
<! DocType html> <html> <head> <meta charset = "utf-8"> <script src = "http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> </script> </head> <body ng-app = "myapp" ng-controller = "myctrl"> <tr ng-repeat = "x in Datensätzen"> <td> {{x.Name}} </td> <td> {{x.country}} </td> </tr> </table> <Script> var App = Angular.modul ("myApp", "myApp", []; Funktion ($ scope) {$ scope.records = [{"name": "alfreds fottterkiste", "Land": "Deutschland"}, {"Name": "Berglunds Snabbk", "Land": "Schweden"}, {"Name": "name": "centro comercial moctezum", ",", "", "", "" "" ". Handel "," Land ":" Österreich "}]}); </script> </body> </html>Auslaufergebnisse:
| Alfreds Futterkiste | Deutschland |
| Berglunds Snabbk | Schweden |
| Centro Comercial Moctezuma | Mexiko |
| Ernst Händel | Österreich |
AngularJS -Instanz
Verwenden Sie ein Objekt, um eine Tabelle auszugeben:
<! DocType html> <html> <head> <meta charset = "utf-8"> <script src = "http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> </script> </head> <body ng-app = "myapp" ng-controller = "myctrl"> <tr ng-repeat = "(x, y) in myObj"> <td> {{x}} </td> <td> {{y}} </td> </tr> </table> <script> var App = Angular.module ("myApp", []; Funktion ($ scope) {$ scope.myobj = {"name": "alfreds fottterkiste", "Land": "Deutschland", "Stadt": "Berlin"}); </script> </body> </html>Auslaufergebnisse:
| Name | Alfreds Futterkiste |
| Land | Deutschland |
| Stadt | Berlin |
Das obige ist die grundlegende Informationen, die die AngularJS NG-Repeat-Richtlinie aussortieren und später ergänzt werden.