Angularjs中ng-repeat的简单实例

时间:2021-05-28

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>

以上就是AngularJs 中ng-repent的使用实例,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章