|
| 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 (condition && string-class) |
| 45 | + </label><br> |
| 46 | + <label> |
| 47 | + <input type="radio" ng-model="benchmark.implementation" value="table"> |
| 48 | + Table ({class: condition}) |
| 49 | + </label><br> |
| 50 | + <label> |
| 51 | + <input type="radio" ng-model="benchmark.implementation" value="list"> |
| 52 | + Todos list ({completed: ..., urgent: ..., ...}) |
| 53 | + </label><br> |
| 54 | + </p> |
| 55 | + |
| 56 | + <br> |
| 57 | + <h3>Example</h3> |
| 58 | + <div ng-switch="benchmark.implementation"> |
| 59 | + <table ng-switch-when="tableOptimized" class="table"> |
| 60 | + <thead> |
| 61 | + <tr> |
| 62 | + <th>todo #id</th> |
| 63 | + <th>completed?</th> |
| 64 | + <th>urgent?</th> |
| 65 | + <th>important?</th> |
| 66 | + </tr> |
| 67 | + </thead> |
| 68 | + <tbody> |
| 69 | + <tr ng-repeat="todo in benchmark.todos track by todo.id" |
| 70 | + ng-class="todo.completed && 'active'" |
| 71 | + ng-class-even="todo.completed && todo.important && 'gold'" |
| 72 | + ng-class-odd="todo.completed && todo.important && 'silver'" |
| 73 | + > |
| 74 | + <td>#{{todo.id}}</td> |
| 75 | + <td>{{todo.completed}}</td> |
| 76 | + <td ng-class="todo.urgent && 'danger'">{{todo.urgent}}</td> |
| 77 | + <td ng-class="todo.important && 'success'">{{todo.important}}</td> |
| 78 | + </tr> |
| 79 | + </tbody> |
| 80 | + </table> |
| 81 | + <table ng-switch-when="table" class="table"> |
| 82 | + <thead> |
| 83 | + <tr> |
| 84 | + <th>todo #id</th> |
| 85 | + <th>completed?</th> |
| 86 | + <th>urgent?</th> |
| 87 | + <th>important?</th> |
| 88 | + </tr> |
| 89 | + </thead> |
| 90 | + <tbody> |
| 91 | + <tr ng-repeat="todo in benchmark.todos track by todo.id" |
| 92 | + ng-class="{active: todo.completed}" |
| 93 | + ng-class-even="{gold: todo.completed && todo.important}" |
| 94 | + ng-class-odd="{silver: todo.completed && todo.important}" |
| 95 | + > |
| 96 | + <td>#{{todo.id}}</td> |
| 97 | + <td>{{todo.completed}}</td> |
| 98 | + <td ng-class="{danger: todo.urgent}">{{todo.urgent}}</td> |
| 99 | + <td ng-class="{success: todo.important}">{{todo.important}}</td> |
| 100 | + </tr> |
| 101 | + </tbody> |
| 102 | + </table> |
| 103 | + <ul ng-switch-when="list"> |
| 104 | + <li ng-repeat="todo in benchmark.todos track by todo.id" |
| 105 | + ng-class="{ |
| 106 | + completed: todo.completed, |
| 107 | + urgent: todo.urgent, |
| 108 | + important: todo.important |
| 109 | + }">#{{todo.id}}</li> |
| 110 | + </ul> |
| 111 | + </div> |
| 112 | + </div> |
| 113 | +</div> |
0 commit comments