Angularjs ng-Reepeatディレクティブ
AngularJSインスタンス
複数のタイトルをループアウトします:
<!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> ng-repeat = "x in records"> {{x}} </h1> <script> var app = angular.module( "myapp"、[]); app.controller( "myctrl"、function($ scope){$ scope.records = ["rookie tutorial 1"、 "rokie tutorial 2" " 4 "、]}); </script> </body> </html>定義と使用法
NG-Reepeatディレクティブは、指定された回数のHTML要素をループアウトするために使用されます。
コレクションは配列またはオブジェクトでなければなりません。
文法
<要素ng-repeat = "expression"> </element>
すべてのHTML要素はこの指令をサポートしています。
パラメーター値
| 価値 | 説明する |
|---|---|
| 表現 | 式は、コレクションをループする方法を定義します。 式インスタンスルール: xレコードの (key、value)myobj x $ $ id(x)によるレコードトラック |
その他の例
AngularJSインスタンス
配列を使用してテーブルをループアウトします。
<!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> ng-repeat = "x in records"> <td> {{x.name}} </td> <td> {{x.country}} </td> </tr> </table> <scrip> var app = angular.module( "name": "alfreds futterkiste"、 "country": "dermany"}、{"name": "berglunds snabbk"、 "country": "name"}、{"name": "centro comecial moctezuma"、 "country": "mexico"}、{"" nertia "" "nenstia": "" ernstia ":" "ernstia" "" ]}); </script> </body> </html>実行結果:
| Alfreds futterkiste | ドイツ |
| Berglunds Snabbk | スウェーデン |
| Centro Comercial Moctezuma | メキシコ |
| エルンストヘンデル | オーストリア |
AngularJSインスタンス
オブジェクトを使用してループしてテーブルを出力します。
<!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> ng-repeat = "(x、y)in myobj"> <td> {{x}} </td> <td> {{y}} </td> </tr> </table> <script> var app = angular.module.module( "myapp"、]); app.controller(myctrl "{$ scope($ scop) "name": "alfreds futterkiste"、 "Country": "ドイツ"、 "City": "Berlin"}}); </script> </body> </html>実行結果:
| 名前 | Alfreds futterkiste |
| 国 | ドイツ |
| 市 | ベルリン |
上記は、Angularjs ng-Reepeatディレクティブを整理する基本情報であり、後で補足されます。