2016년 1월 26일 화요일

[AngularJS] Event

click event : ngClick, ngDblClick
Mouse event : ngMouseDown, up, enter, leave, move, Over
keyBoard event : ngKeyDown, up, press
Change event : ngChange

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
<!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">  
    <ul class="list-group">
      <li ng-repeat='grade in gradeList' 
          class="list-group-item" 
          ng-click="showGrade(grade)">
        {{grade.subject}}
        <!-- isShow 변수가 true인가 false인지에 따라서 show/ hide -->
        <p ng-if='grade.isShow'class="badge"> {{ grade.grade}}</p>
      </li>
    </ul>
  </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.gradeList = [
      {"subject":"Korean""grade":"A"},
      {"subject":"Engilsh""grade":"B"},
      {"subject":"Math""grade":"C"},
      {"subject":"Science""grade":"D"}
    ];
    $scope.showGrade = function(grade) {
      console.dir(grade);
      grade.isShow = grade.isShow?!grade.isShow:true;
    };
  }); 
  </script>
  </body>
</html>
cs

댓글 없음:

댓글 쓰기