-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex08-inject-resolved.html
88 lines (77 loc) · 2.37 KB
/
ex08-inject-resolved.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
84
85
86
87
<!doctype html>
<html data-ng-app="workshopBeMEAN">
<head>
<title>{{ workshop }}</title>
</head>
<body>
<div data-ng-controller='BeerController'>
{{ cervejas }}
<pre>Ordenando por predicate = {{predicate}}; reverse = {{reverse}}</pre>
<table>
<thead>
<tr>
<th data-ng-click="ordenar('name')">Name</th>
<th data-ng-click="ordenar('price')">Price</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat='cerveja in cervejas | orderBy:predicate:reverse'>
<td>{{ cerveja.name }}</td>
<td>{{ cerveja.price }}</td>
</tr>
</tbody>
</table>
</div>
<script src="angular.min.js"></script>
<script>
angular.module('workshopBeMEAN', ['workshopFilters'])
.controller('BeerController', BeerController);
function BeerController ($scope){
$scope.reverse = false;
$scope.predicate = 'name';
$scope.ordenar = function(predicate) {
$scope.predicate = predicate;
$scope.reverse = !$scope.reverse
}
// criamos um array de cervejas
var cervejas = [{
name: 'Kaiser', price: 2
}, {
name: 'Skol', price: 3
}, {
name: 'Glacial', price: 4
}, {
name: 'Polar', price: 6
}, {
name: 'Heineken', price: 10
}
];
// instanciamos nosso array no nosso scope
// para que tenhamos acesso à esse array na View
$scope.cervejas = cervejas;
};
BeerController['$inject'] = ['$scope'];
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>