javascript - Angularjs - Get URL parameters from inside the when() function -
javascript - Angularjs - Get URL parameters from inside the when() function -
given next code:
$routeprovider.when('/movies/:type', { title: 'movies', templateurl: 'pages/movies/movies.html', controller: 'moviesctrl' }); how can access :type param within when function? want so:
$routeprovider.when('/movies/:type', { title: 'movies' + ' - ' + :type, templateurl: 'pages/movies/movies.html', controller: 'moviesctrl' }); that value in title must dinamically generated.
thanks in adv.
i'm not sure why extending route (config) object, able access routeparams within controller. recommended way.
the $routeparams service allows retrieve current set of route parameters.
angular.module('mymodule').controller('moviesctrl',function($scope, $routeparams) { $scope.currentmovietype = 'filmes-' + $routeparams.type; }); let's route /movies/scifi. in case $scope.currentmovietype becomes scifi , can utilize {{currentmovietype}} in view populate value. can find detailed informations in documentation.
note $routeparams updated after route alter completes successfully. means cannot rely on $routeparams beingness right in route resolve functions. instead can utilize $route.current.params access new route's parameters.
javascript angularjs angular-routing
Comments
Post a Comment