I'm currently working on a controller that needs to access a URL parameter, but I've hit a roadblock in figuring out how to retrieve this parameter. Here's what I have attempted so far:
Controller:
function CustomerCtrl($scope, $http, $routeParams, $route) {
// var customer_id = $routeParams.id; // unable to make this work
// var customer_id = $route.current.params.id; // also unsuccessful
var customer_id = '58'; // however, this approach seems to be effective
$http({
url: 'customers/' + customer_id + '/info',
method: "POST"
})
.success(function (data, status, headers, config) { $scope.name = data; })
.error(function (data, status, headers, config) { $scope.status = status; });
}
App:
var customer = {
name: 'customer',
url: '/customer',
abstract: true,
templateUrl: 'views/customer/customer.html',
controller: 'CustomerCtrl'
};
var customer_info = {
name: 'customer.info',
parent: customer,
url: '/:id/info'
views: {
view1: { templateUrl: "views/customer/view1.html" },
view2: { templateUrl: "views/customer/view2.html" }
}
};
$stateProvider
.state(customer)
.state(customer_info);
Can anyone point out where I might be going wrong in my implementation?