Directive Angularjs Ng-Repeat
Instance angularjs
Louler plusieurs titres:
<! Doctype html> <html> <éad> <meta charset = "utf-8"> <script src = "http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> </script> ng-repeat = "x dans les enregistrements"> {{x}} </h1> <script> var app = angular.module ("myapp", []); app.Controller ("myctrl", fonction ($ scope) {$ scope.records = ["Rookie Tutorial 1", "Rokie Tutorial 2", "Rookie Tutorial 3", "ROCORAL ]}); </cript> </ body> </html>Définition et utilisation
La directive Ng-Repeat est utilisée pour éloigner les éléments HTML d'un nombre spécifié de fois.
La collection doit être un tableau ou un objet.
grammaire
<élément ng-repeat = "expression"> </element>
Tous les éléments HTML prennent en charge cette directive.
Valeur du paramètre
| valeur | décrire |
|---|---|
| Expression | Les expressions définissent comment faire boucle une collection. Règles d'instance d'expression: x dans les disques (clé, valeur) dans myobj X In Records Track par $ id (x) |
Plus d'exemples
Instance angularjs
Utilisez un tableau pour éteindre une table:
<! Doctype html> <html> <éadf> <meta charset = "utf-8"> <script src = "http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> </cript> </ad> <body ng-app = "MyApp"> <Table Ng-Controller = "MyCtrl"> <tr ng-repeat = "x dans les enregistrements"> <td> {{x.name}} </td> <td> {{X.Country}} </td> </tr> </ table> <cript> var app = angular.Module ("MyApp", []); app.Contrer ("MyCrl fonction ($ scope) {$ scope.records = [{"name": "Alfreds Futterkiste", "country": "allemy"}, {"name": "bergluds snabbk", "country": "Sweden"},, {"name": "Centro Commercial MoctEzuma" " Handel "," country ":" Austria "}]}); </cript> </ody> </html>Résultats en cours:
| Alfreds Futterkiste | Allemagne |
| Bergluds snabbk | Suède |
| Centro Comercial Moctezuma | Mexique |
| Ernst Handel | Autriche |
Instance angularjs
Utilisez un objet pour faire boucle pour sortir un tableau:
<! Doctype html> <html> <éadf> <meta charset = "utf-8"> <script src = "http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> </cript> </ad> <body ng-app = "MyApp"> <Table ng-controlller = "myctrl"> <tr ng-repeat = "(x, y) dans myobj"> <td> {{x}} </td> <td> {{y}} </td> </tr> </ table> <cript> var app = angular.module ("MyApp", []); app.Contrer ("myctrl", "MyApp", []); app.Controller ("MyCrl fonction ($ scope) {$ scope.myoBj = {"name": "Alfreds Futterkiste", "country": "Allemagne", "ville": "berlin"}}); </cript> </ body> </html>Résultats en cours:
| Nom | Alfreds Futterkiste |
| Pays | Allemagne |
| Ville | Berlin |
Ce qui précède est le tri des informations de base de la directive AngularJS NG-Repeat, et sera complété plus tard.