|
| 1 | +<!DOCTYPE html> |
| 2 | +<html ng-app="exampleApp"> |
| 3 | +<head> |
| 4 | + <title>Directives</title> |
| 5 | + <script src="angular.js"></script> |
| 6 | + <link href="bootstrap.css" rel="stylesheet" /> |
| 7 | + <link href="bootstrap-theme.css" rel="stylesheet" /> |
| 8 | + <script> |
| 9 | + angular.module("exampleApp", []) |
| 10 | + .controller("defaultCtrl", function ($scope) { |
| 11 | + |
| 12 | + $scope.data = {}; |
| 13 | + // data라는 값을 선언해 빈 값으로 만들어 두었다. |
| 14 | + |
| 15 | + $scope.todos = [ |
| 16 | + { action: "Get groceries", complete: false }, |
| 17 | + { action: "Call plumber", complete: false }, |
| 18 | + { action: "Buy running shoes", complete: true }, |
| 19 | + { action: "Buy flowers", complete: false }, |
| 20 | + { action: "Call family", complete: false }]; |
| 21 | + }); |
| 22 | + </script> |
| 23 | +</head> |
| 24 | +<body> |
| 25 | + <div id="todoPanel" class="panel" ng-controller="defaultCtrl"> |
| 26 | + |
| 27 | + <h3 class="panel-header">To Do List</h3> |
| 28 | + |
| 29 | + <div class="well"> |
| 30 | + <div class="radio" ng-repeat="button in ['None', 'Table', 'List']"> |
| 31 | + <label> |
| 32 | + <input type="radio" ng-model="data.mode" |
| 33 | + value="{{button}}" ng-checked="$first" /> |
| 34 | + {{button}} |
| 35 | + </label> |
| 36 | + <!-- radio버튼을 ng-repeat를 이용해 만들어내고 |
| 37 | + 그 값을 data.mode에 저장하게 된다. --> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + |
| 41 | + <!-- 아래의 예제는 ng-switch를 이용해 on에 들어가는 값에 따라 |
| 42 | + div를 선택할 수 있도록 하는 예제이다. --> |
| 43 | + <div ng-switch on="data.mode"> |
| 44 | + <div ng-switch-when="Table"> |
| 45 | + <table class="table"> |
| 46 | + <thead> |
| 47 | + <tr><th>#</th><th>Action</th><th>Done</th></tr> |
| 48 | + </thead> |
| 49 | + <tr ng-repeat="item in todos" ng-class="$odd ? 'odd' : 'even'"> |
| 50 | + <td>{{$index + 1}}</td> |
| 51 | + <td ng-repeat="prop in item">{{prop}}</td> |
| 52 | + </tr> |
| 53 | + </table> |
| 54 | + </div> |
| 55 | + <div ng-switch-when="List"> |
| 56 | + <ol> |
| 57 | + <li ng-repeat="item in todos"> |
| 58 | + {{item.action}}<span ng-if="item.complete"> (Done)</span> |
| 59 | + </li> |
| 60 | + </ol> |
| 61 | + </div> |
| 62 | + <div ng-switch-default> |
| 63 | + Select another option to display a layout |
| 64 | + </div> |
| 65 | + </div> |
| 66 | + |
| 67 | + </div> |
| 68 | +</body> |
| 69 | +</html> |
0 commit comments