I am faced with the challenge of passing the last parameter from the following URL to a $http.get request in my Angular application.
http://myurl.dev/users/32
However, I am struggling to figure out how to pass the 32
as the id.
Here is what I have tried so far:
var matchmaker = angular.module('matchmaker', ['ngRoute'], function($interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
})
.controller('LocationCtrl', ['$scope', '$http', '$location', '$routeParams', '$route', function($scope, $http, $location, $routeParams, $route) {
var id = $route.current.params.id;
console.log(id);
$http.get('http://myurl.dev/services/' + id ).success(function(data)
{
$scope.applicants = data;
});
}]);
Unfortunately, I'm receiving the following error in the console:
Cannot read property 'params' of undefined
If anyone can provide insight into what might be going wrong, I would greatly appreciate it.
Edit:
Note that the URL being used is generated on the server side, not by Angular.
Edit 2.0
For reference, here is the configuration for the routeProvider with actual route parameters:
var matchmaker = angular.module('matchmaker', ['ngRoute'], function($interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
})
.config(function($routeProvider, $locationProvider) {
$routeProvider.when('/matchmaker/locations/:id', {
controller: 'LocationCtrl'
});
$locationProvider.html5Mode(true);
});