Mr. Felix Mr. Felix - 1 month ago 10
AngularJS Question

Angular ui-router pass parameter within the URL

I know I can pass parameters when changing pages like this:

$state.go('index.my_route', {my_param : value});


then:

function myCtrl($stateParams) {
console.log($stateParams.my_param);
}


But I need this parameter at URL then I would like to know how can I pass it with the URL string and still calling
$state.go
. Something like this:

$state.go('index.my_route?my_param=' + value);
> "http://localhost/#/index/my_route?my_param=123"

Answer

Your route should have url with query parameter.

.state('index.my_route', {
   url: '/index/my_route?my_param',
   ....
});

Now can call the state in the same way using $state.go with parameters.