792 B
792 B
.cadoles-slide-title[Routage dans le navigateur (3/3)]
Navigation & récupération des paramètre des routes
- Le service
$location
permet de récupérer des informations sur la route courante et de naviguer dans l'application. - Le service
$routeParams
est un objet clé/valeur qui porte les paramètres associés à la route courante.
// En assumant l'URL suivante: http://localhost/myApp/#/my/path/foo
// et la définition de route /my/path/:myParam
angular.module('myApp', ['ngRoute'])
.controller('MainCtrl', ['$location', '$routeParams', function($location, $routeParams) {
$location.path(); // -> /my/path/foo
$routeParams.myParam; // -> "foo"
$location.path('/my/other/path'); // "Navigue" vers http://localhost/myApp/#/my/other/path
}])
;