您好,登錄后才能下訂單哦!
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的使用實例,如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。