编辑这个页面须要登录或更高权限!
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script> </head> <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 = [ "基础教程网1", "基础教程网2", "基础教程网3", "基础教程网4", ] }); </script> </body> </html>测试看看 ‹/›
ng-repeat 指令用于循环输出指定次数的 HTML 元素。
集合必须是数组或对象。
<element ng-repeat="expression"></element>
所有的 HTML 元素都支持该指令。
值 | 描述 |
---|---|
expression | 表达式定义了如何循环集合。 表达式示例规则: x in records
(key, value) in myObj |
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script> </head> <body ng-app="myApp"> <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", "Country" : "Sweden" }, { "Name" : "Centro comercial Moctezuma", "Country" : "Mexico" }, { "Name" : "Ernst Handel", "Country" : "Austria" } ] }); </script> </body> </html>测试看看 ‹/›
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script> </head> <body ng-app="myApp"> <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> </body> </html>测试看看 ‹/›