I'm using AngularJS's ui-router in my webapp. I have a state that looks like this:
$stateProvider.state('mystate',
{
url: '/mystate/{id:int}/:slug',
params: {
slug: {value: null, squash: true}
},
templateUrl: 'partials/mystate.html',
controller: 'MyStateCtrl'
}
);
I can link to this state in my view like this:
<a ui-sref="mystate({id: 4, slug: 'myslug'})">Hello World</a>
It converts it to the following URL: /mystate/4/myslug/
I want to build the same URL that ui-sref
produces, but I want it inside MyStateCtrl
. How do I do that? In the controller, I have access to $stateParams.id
and $stateParams.slug
. But what function do I need to call to convert them to that URL?
EDIT: Please note: I do not want to go to the resultant URL. I just want to have it for later use.