1. 程式人生 > >AngularJS1學習-常用指令(四)

AngularJS1學習-常用指令(四)

nbsp text one ng-repeat asc ava 常用 java 常用指令

1.循環數組

 1 <script type="text/javascript">
 2     //定義一個叫myApp的模塊
 3     var app = angular.module(‘myApp‘,[]);
 4     //定義控制器
 5     app.controller(‘myController‘,function($scope){
 6         $scope.list=[100,101,102,103,104]//定義數組
 7                 
 8     })
 9             
10 </script>
11 
12 <body ng-app="myApp" ng-controller="myController">
13
<table > 14 <tr ng-repeat="c in list"> 15 16 <td>{{c}}</td> 17 18 </tr> 19 </table> 20 </body>

2.循環對象數組

<script type="text/javascript">
     //定義模塊
    var app =  angular.module("myModu",[]);
    
//定義控制器 app.controller("contrl3",function($scope){ //定義對象數組 $scope.list=[ {name:‘習大大‘,power:99,money:98}, {name:‘特朗普‘,power:100,money:99}, {name:‘普京‘,power:100,money:96}, {name:‘金三胖‘,power:70,money:50} ]; }) </script> <body ng-app="myModu" ng-controller="contrl3"> <table > <tr> <td>姓名</td> <td>權力</td> <td>金錢</td> </tr> <tr ng-repeat="pe in list"> <td>{{pe.name}}</td> <td>{{pe.power}}</td> <td>{{pe.money}}</td> </tr> </table> </body>

AngularJS1學習-常用指令(四)