|
| 1 | +<style> |
| 2 | + .gold { |
| 3 | + background: gold; |
| 4 | + } |
| 5 | + .silver { |
| 6 | + background: silver; |
| 7 | + } |
| 8 | + .table tbody tr > td.success { |
| 9 | + background-color: #dff0d8; |
| 10 | + } |
| 11 | + |
| 12 | + .table tbody tr > td.error { |
| 13 | + background-color: #f2dede; |
| 14 | + } |
| 15 | + |
| 16 | + .table tbody tr > td.warning { |
| 17 | + background-color: #fcf8e3; |
| 18 | + } |
| 19 | + |
| 20 | + .table tbody tr > td.info { |
| 21 | + background-color: #d9edf7; |
| 22 | + } |
| 23 | + .completed { |
| 24 | + text-decoration: line-through; |
| 25 | + } |
| 26 | + .important { |
| 27 | + font-weight: bold; |
| 28 | + } |
| 29 | + .urgent { |
| 30 | + color: red; |
| 31 | + } |
| 32 | +</style> |
| 33 | +<div ng-app="ngClassBenchmark" ng-cloak> |
| 34 | + <div ng-controller="DataController as benchmark"> |
| 35 | + <h3>Parameters</h3> |
| 36 | + <p> |
| 37 | + <label>Number of todos</label><br> |
| 38 | + <input type="number" ng-model="benchmark.numberOfTodos"> |
| 39 | + </p> |
| 40 | + <p> |
| 41 | + Implementation:<br> |
| 42 | + <label> |
| 43 | + <input type="radio" ng-model="benchmark.implementation" value="tableOptimized"> |
| 44 | + Table optimized <code>ng-class="'success' && todo.completed"</code> |
| 45 | + </label><br> |
| 46 | + <label> |
| 47 | + <input type="radio" ng-model="benchmark.implementation" value="table"> |
| 48 | + Table <code>ng-class="{success: todo.completed}"</code> |
| 49 | + </label><br> |
| 50 | + <label> |
| 51 | + <input type="radio" ng-model="benchmark.implementation" value="list"> |
| 52 | + Table <code>ng-class="{completed: todo.completed, urgent: todo.urgent, important: todo.important"}</code> |
| 53 | + </label><br> |
| 54 | + <label> |
| 55 | + <input type="radio" ng-model="benchmark.implementation" value="singleOptimized"> |
| 56 | + Single ngClass Optimized <code>ng-class="{'panel-success': !!benchmark.todos, 'panel-error': !benchmark.todos}"</code> |
| 57 | + </label><br> |
| 58 | + <label> |
| 59 | + <input type="radio" ng-model="benchmark.implementation" value="single"> |
| 60 | + Single ngClass <code>ng-class="{'panel-success': benchmark.todos, 'panel-error': !benchmark.todos}"</code> |
| 61 | + </label><br> |
| 62 | + |
| 63 | + </p> |
| 64 | + |
| 65 | + <br> |
| 66 | + <h3>Example</h3> |
| 67 | + <div ng-switch="benchmark.implementation"> |
| 68 | + <table ng-switch-when="tableOptimized" class="table"> |
| 69 | + <thead> |
| 70 | + <tr> |
| 71 | + <th>todo #id</th> |
| 72 | + <th>completed?</th> |
| 73 | + <th>urgent?</th> |
| 74 | + <th>important?</th> |
| 75 | + </tr> |
| 76 | + </thead> |
| 77 | + <tbody> |
| 78 | + <tr ng-repeat="todo in benchmark.todos track by todo.id" |
| 79 | + ng-class="todo.completed && 'active'" |
| 80 | + ng-class-even="todo.completed && todo.important && 'gold'" |
| 81 | + ng-class-odd="todo.completed && todo.important && 'silver'" |
| 82 | + > |
| 83 | + <td>#{{todo.id}}</td> |
| 84 | + <td>{{todo.completed}}</td> |
| 85 | + <td ng-class="todo.urgent && 'danger'">{{todo.urgent}}</td> |
| 86 | + <td ng-class="todo.important && 'success'">{{todo.important}}</td> |
| 87 | + </tr> |
| 88 | + </tbody> |
| 89 | + </table> |
| 90 | + <table ng-switch-when="table" class="table"> |
| 91 | + <thead> |
| 92 | + <tr> |
| 93 | + <th>todo #id</th> |
| 94 | + <th>completed?</th> |
| 95 | + <th>urgent?</th> |
| 96 | + <th>important?</th> |
| 97 | + </tr> |
| 98 | + </thead> |
| 99 | + <tbody> |
| 100 | + <tr ng-repeat="todo in benchmark.todos track by todo.id" |
| 101 | + ng-class="{active: todo.completed}" |
| 102 | + ng-class-even="{gold: todo.completed && todo.important}" |
| 103 | + ng-class-odd="{silver: todo.completed && todo.important}" |
| 104 | + > |
| 105 | + <td>#{{todo.id}}</td> |
| 106 | + <td>{{todo.completed}}</td> |
| 107 | + <td ng-class="{danger: todo.urgent}">{{todo.urgent}}</td> |
| 108 | + <td ng-class="{success: todo.important}">{{todo.important}}</td> |
| 109 | + </tr> |
| 110 | + </tbody> |
| 111 | + </table> |
| 112 | + <ul ng-switch-when="list"> |
| 113 | + <li ng-repeat="todo in benchmark.todos track by todo.id" |
| 114 | + ng-class="{ |
| 115 | + completed: todo.completed, |
| 116 | + urgent: todo.urgent, |
| 117 | + important: todo.important |
| 118 | + }">#{{todo.id}}</li> |
| 119 | + </ul> |
| 120 | + <div ng-switch-when="singleOptimized" class="panel" |
| 121 | + ng-class="{'panel-success': !!benchmark.todos, 'panel-error': !benchmark.todos}"> |
| 122 | + <div class="panel-heading"> |
| 123 | + <h3 class="panel-title">Information</h3> |
| 124 | + </div> |
| 125 | + <div class="panel-body"> Panel content </div> |
| 126 | + </div> |
| 127 | + <div ng-switch-when="single" class="panel" |
| 128 | + ng-class="{'panel-success': benchmark.todos, 'panel-error': !benchmark.todos}"> |
| 129 | + <div class="panel-heading"> |
| 130 | + <h3 class="panel-title">Information</h3> |
| 131 | + </div> |
| 132 | + <div class="panel-body"> Panel content </div> |
| 133 | + </div> |
| 134 | + </div> |
| 135 | + </div> |
| 136 | +</div> |
0 commit comments