Diretiva AngularJS ng-repeat
Instância de AngularJS
Loop Out vários títulos:
<! 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-n-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N- NG-N-N-N-N-N-N-N-N-N- NG-N-N- NG- NG- = " ng-Controller = "myctrl"> <h1 ng-repeat = "X in Records"> {{x}} </h1> <cript> var app = angular.module ("myApp", []); App.Controller ("myctrling (myctrling (myctrling ($ scope", []); "Tutorial de Rookie 3", "Tutorial de Rookie 4",]}); </script> </body> </html>Definição e uso
A diretiva NG-Repeat é usada para realizar os elementos HTML de um número especificado de vezes.
A coleção deve ser uma matriz ou objeto.
gramática
<elemento ng-repeat = "Expression"> </lement>
Todos os elementos HTML suportam esta diretiva.
Valor do parâmetro
| valor | descrever |
|---|---|
| Expressão | Expressões definem como fazer loop uma coleção. Regras da instância da expressão: x em registros (chave, valor) em myobj X na rastreamento dos registros por $ id (x) |
Mais exemplos
Instância de AngularJS
Use uma matriz para fazer uma tabela:
<! Doctype html> <html> <head> <meta charset = "utf-8"> <script src = "http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> </cript> </head> <body Ng-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-NG-N-N- NG- NG-NG = " ng-CONTROLLER = "myctrl"> <tr ng-repeat = "X in Records"> <td> {{x.name}} </td> <td> {{x.country}}} </td> </try </tabela </script> varp = angular.module " function ($ scope) {$ scope.records = [{"name": "alfreds futterkiste", "country": "Alemanha"}, {"name": "berglunds snabbk," country ":" sueden "}," "": "" Centro Comocial "": country ", country" {"" ":" "Centro Comocial" " "Ernst Handel", "Country": "Áustria"}]}); </sCript> </body> </html>Resultados em execução:
| Alfreds Futterkiste | Alemanha |
| Berglunds Snabbk | Suécia |
| Centro Comercial Moctezuma | México |
| Ernst Handel | Áustria |
Instância de AngularJS
Use um objeto para fazer loop para produzir uma tabela:
<! Doctype html> <html> <head> <meta charset = "utf-8"> <script src = "http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> </cript> </head> <body Ng-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-N-NG-N-N- NG- NG-NG = " ng-CONTROLLER = "myctrl"> <tr ng-repeat = "(x, y) em myobj"> <td> {{x}} </td> <td> {{y}}} </td> </trd> </script> var = angular.module " function ($ scope) {$ scope.myobj = {"name": "Alfreds Futterkiste", "país": "Alemanha", "City": "Berlin"}}); </sCript> </body> </html>Resultados em execução:
| Nome | Alfreds Futterkiste |
| País | Alemanha |
| Cidade | Berlim |
O exposto acima está as informações básicas que classificam a diretiva AngularJS NG-REPEAT e serão complementadas posteriormente.