-
Notifications
You must be signed in to change notification settings - Fork 0
/
exemplo 9.1 – rotas-hashbang.html
99 lines (88 loc) · 2.47 KB
/
exemplo 9.1 – rotas-hashbang.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
88
89
90
91
92
93
94
95
96
97
98
99
<!doctype html>
<html ng-app="myApp">
<style>
ul {
float: left;
width: 100%;
padding: 0;
margin: 0 0 10px 0;
list-style-type: none;
}
a {
float: left;
text-decoration: none;
color: white;
background-color: #3C599B;
padding: 0.2em 0.6em;
border-right: 1px solid white;
width: auto 100%;
}
a:hover {
background-color: #61749F;
}
li {
display: inline;
width: auto 100%;
}
#ng-view {
background-color: #E7ECF2;
padding: 5px;
margin: 10px;
}
pre {
font-family: "Lucida Console", arial, sans;
font-size: 11px;
}
</style>
<body>
<div ng-controller="PaginaPrincipalController">
<ul>
<li><a href="#!/livro/1"> Livro 1</a></li>
<li><a href="#!/livro/1/capitulo/2"> Livro 1 Capítulo 2</a></li>
<li><a href="#!/linkquebrado/1"> Link Quebrado (otherwise route)</a></li>
</ul>
<!-- conteudo do template da rota, armazenado em ng-view -->
<div id="ng-view" ng-view></div>
<fieldset>
<legend>Alguns dados de $route e $routeParams</legend>
<pre>$route.current.templateUrl = {{$route.current.templateUrl}}</pre>
<pre>$route.current.params = {{$route.current.params}}</pre>
<pre>$routeParams = {{$routeParams}}</pre>
</fieldset>
</div>
<script src="angular.min.js"></script>
<script src="angular-route.min.js"></script>
<script type="text/javascript">
var app = angular.module('myApp', ['ngRoute'])
.controller('PaginaPrincipalController', ['$scope','$route','$routeParams', function($scope, $route, $routeParams) {
$scope.$route = $route;
$scope.$routeParams = $routeParams;
}])
.controller('LivroController', ['$scope','$routeParams', function($scope, $routeParams) {
$scope.nome = "LivroController";
$scope.parametros = $routeParams;
}])
.controller('CapituloController', ['$scope','$routeParams', function($scope, $routeParams) {
$scope.nome = "CapituloController";
$scope.parametros = $routeParams;
}])
.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
// configura hashbang prefix
$locationProvider.hashPrefix('!');
// inicio da configuracao de rotas
$routeProvider
.when('/livro/:id', {
templateUrl: 'livro.html',
controller: 'LivroController'
})
.when('/livro/:idLivro/capitulo/:idCap', {
templateUrl: 'capitulo.html',
controller: 'CapituloController'
})
.otherwise({
redirectTo: '/'
});
}]);
</script>
</body>
</html>