您好,欢迎来到好走旅游网。
搜索
您的当前位置:首页Angularjs中ng-repeat的简单实例

Angularjs中ng-repeat的简单实例

来源:好走旅游网

Angularjs中ng-repeat的简单实例

第一个例子:使用ng-repeat最简单的例子

<html ng-app="myApp">
<head>
<title>angularjs-demo</title>
<script type="text/javascript" src="angular.min.js" charset="utf-8"></script>
</head>
<body ng-controller="ctrl">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
 <tr>
 <th>学号</th>
 <th>姓名</th>
 <th>分数</th>
 </tr>
 <tr ng-repeat="item in items">
 <td>{{item.id}}</td>
 <td>{{item.name}}</td>
 <td>{{item.score}}</td>
 </tr>
</table>
<script>
 var app = angular.module('myApp',[]);
 app.controller("ctrl",function($scope,$location){
 $scope.items = getStu();
 });
 
 function getStu() {
 return [{id:1010,name:'张三',score:50},{id:1011,name:'李四',score:60},{id:1012,name:'王五',score:80}];
 }
 </script>
</body>
</html>

第二个例子:添加过滤条件

<html ng-app="myApp">
<head>
<title>angularjs-demo</title>
<script type="text/javascript" src="angular.min.js" charset="utf-8"></script>
</head>
<body ng-controller="ctrl">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
 <tr>
 <th>学号</th>
 <th>姓名</th>
 <th>分数</th>
 </tr>
 <tr ng-repeat="item in items | filter:fscore">
 <td>{{item.id}}</td>
 <td>{{item.name}}</td>
 <td>{{item.score}}</td>
 </tr>
</table>
<script>
 var app = angular.module('myApp',[]);
 app.controller("ctrl",function($scope,$location){
 $scope.items = getStu();
 $scope.fscore = function(e) {
 return e.score>=60;
 }
 });
 
 function getStu() {
 return [{id:1010,name:'张三',score:50},{id:1011,name:'李四',score:60},{id:1012,name:'王五',score:80}];
 }
 </script>
</body>
</html>

Copyright © 2019- haog.cn 版权所有 赣ICP备2024042798号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务