2016년 1월 26일 화요일

[AngularJS] ngRepeatStart, ngRepeatEnd


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html >
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
  </head>
  <body ng-app='gradeApp'>
  <div class="panel panel-primary" ng-controller='GradeController'>
  <div class="panel-heading">Your Grade</div>  
  <div class="panel-body">
    <!-- key를 지정하지 않으면, 0, 1, 2, 3이 출력된다. -->
    <table class=table>
      <tr ng-repeat='(key, value) in ["AAA","BBB","CCC","DDD"]'>
        <td > {{key}} </td>
        <td> {{value}} </td>        
      </tr>      
    </table>
    <!-- key를 지정하면, 키와 value가 출력된다 -->
    <table class=table>
      <tr ng-repeat='(key, value) in {"subject":"Korean", "grade":"A", "name":"jteve"}'>
        <td > {{key}} </td>
        <td> {{value}} </td>        
      </tr>      
    </table>
    <!-- ng-repeat -->
    <table class=table>
      <tr ng-repeat='grade in grades'  class="{{$even?'active':'warning'}}">
        <td> {{$index}} </td>
        <td > {{grade.subject}} </td>
        <td> {{grade.grade}} </td>
      </tr>
    </table>
    <!-- 반복적으로 종료에 무언가를 나타내야할 때 사용가능 -->
    <p ng-repeat-start="grade in grades">start</p>
    {{grade.subject}}
    <p ng-repeat-end>end</p>
    </div>
    </div>   
    <script src="http://code.angularjs.org/1.2.11/angular.min.js"></script>
    <script src="http://code.angularjs.org/1.2.11/angular-sanitize.min.js"></script>    
    <script>
    var grade  = angular.module('gradeApp',[]); 
    grade.controller('GradeController'function($scope){
      $scope.grades = [
        {"subject":"Korean""grade":"A"},
        {"subject":"Engilsh""grade":"B"},
        {"subject":"Math""grade":"C"},
        {"subject":"Science""grade":"D"}
      ];
      console.log($scope.grades);
    }); 
    </script>
  </body>
</html>
cs


댓글 없음:

댓글 쓰기