Angularjs Retrieving param from routeProvider
angularjs, parameters, route-provider
Solution
It's all in the docs:
Be aware that `ngRoute.$routeParams` will still refer to the previous route within these resolve functions. Use `$route.current.params`.
E.g.:
resolve: {
studentID: function ($route) {
return $route.current.params.id;
}
...
}
See, also this short demo.
Problem
Quick question, is it possible to get a param from a $routeProvider at the below stage? ``` app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) { $routeProvider .when('/', { templateUrl: 'views/home.html', controller: 'IndexController' }) .when('/students/:id', { templateUrl: 'views/studentRecord.html', controller: 'StudentsController', resolve: { students: function(getStudents) { return getStudents.getAllStudents(); }, movies: function(getStudents,$stateParams) { return getStudents.getStudentbyId($stateParams.id); } } }); $locationProvider.html5Mode(true); ``` }]); So where i have 'getStudentbyId(5)' ideally i'd want to get the :id value field. After a good amount of googling i cannot find a way. Any ideas? Cheers EDIT: when injecting $stateParams in my app.config i get '(anonymous function) angular.js:78' same as when i used $params.. eg. ``` app.config(['$routeProvider', '$locationProvider', '$stateParams', function($routeProvider, $locationProvider, $stateParams) { ```