-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex09-a.html
executable file
·84 lines (73 loc) · 2.31 KB
/
ex09-a.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!doctype html>
<html data-ng-app="workshopBeMEAN">
<title>{{ workshop }}</title>
<body>
<div data-ng-controller='BeerController'>
<!-- Exibição do array de cervejas setado no BeerController -->
{{ cervejas }}
<pre>Sorting predicate = {{predicate}}; reverse = {{reverse}}</pre>
<!-- <a href="" data-ng-click="predicate = 'name'; reverse=!reverse">Nome</a> -->
<table>
<thead>
<tr>
<th data-ng-click='ordenar("name")'>Nome</th>
<th data-ng-click='ordenar("price")'>Preço</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat='beer in cervejas | orderBy:predicate:reverse'>
<td>{{ beer.name }}</td>
<td>{{ beer.price }}</td>
</tr>
</tbody>
</table>
</div>
<script src="angular.min.js"></script>
<script>
angular.module('workshopBeMEAN', ['workshopFilters', 'workshopControllers']);
angular.module('workshopControllers', [])
.controller('BeerController', ['$scope',
function($scope){
$scope.reverse = true;
$scope.predicate = 'name';
$scope.ordenar = function(predicado){
$scope.reverse = !$scope.reverse;
$scope.predicate = predicado;
}
$scope.cervejas = [{
name: 'Kaiser', price: 2
}, {
name: 'Skol', price: 3
}, {
name: 'Glacial', price: 4
}, {
name: 'Polar', price: 6
}, {
name: 'Heineken', price: 10
}
];
}]);
angular.module('workshopFilters', [])
.filter('reverseName', function () {
return function (text) {
if(text)
return text.split("").reverse().join("");
};
})
.filter('truncate', function () {
return function (text, length, end) {
if (isNaN(length))
length = 10;
if (end === undefined)
end = "...";
if (text.length <= length || text.length - end.length <= length) {
return text;
}
else {
return String(text).substring(0, length-end.length) + end;
}
};
});
</script>
</body>
</html>