-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex08.html
executable file
·76 lines (66 loc) · 2.12 KB
/
ex08.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
<!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>
<a href="" data-ng-click="predicate = 'price'; reverse=!reverse">Ordenar por: {{ predicate }}</a>
<ul>
<!-- Parecido com o nosso for no Jade -->
<li data-ng-repeat='cerveja in cervejas | orderBy:predicate:reverse'>
<!-- acessando os valores do array -->
{{ cerveja.name }} - {{ cerveja.price }}
</li>
</ul>
</div>
<script src="angular.min.js"></script>
<script>
angular.module('workshopBeMEAN', ['workshopFilters'])
.controller('BeerController', ['$scope', BeerController]);
function BeerController($scope){
$scope.reverse = false;
$scope.predicate = 'name';
// 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;
}
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>