Reputation: 641
I got this URL into my system:
http://localhost/myapp/#/campaign/confirm/edit/:id
What are the best ways to get campaign
, confirm
and edit
inside my controller?
Upvotes: 2
Views: 696
Reputation: 3651
Looks like you've got this url formatted as an angular state (awesome!). In this case, you can access $stateParams in your controller.
https://github.com/angular-ui/ui-router/wiki/URL-Routing#stateparams-service
That should have the information you need, assuming your state is something like this. This example makes all 4 parts into accessible variables, that's if you really do need ALL parts of that path. It's probably worth putting in some non-variable data in there, otherwise it might get a little difficult to separate this state from others that are formed in a similar way:
$stateProvider.state('myStateName', {
url: '{campaign}/{confirm}/{edit}/{id}'
});
myModule.controller('fooCtrl', function($scope, $stateParams){
console.log(
$stateParams.campaign,
$stateParams.confirm,
$stateParams.edit,
$stateParams.id);
});
Upvotes: 1