Bazinga
Bazinga

Reputation: 11224

Angular ui router change state with query params

How i can go to a state and add query params to the url at the same time? Lets say i have this state:

$stateProvider
           .state('cart', {
            templateUrl: 'client/cart/cart.html',
            url: '/my-cart',           
            controller: 'CartController'
        })

I want from some views to $state.go('cart') and from some views to $state.go('cart') but with query params added to it like, /cart?purchase=complete

Upvotes: 3

Views: 1171

Answers (2)

Bazinga
Bazinga

Reputation: 11224

So i found the answer, i hope it will help for someone else.

$stateProvider
           .state('cart', {
            templateUrl: 'client/cart/cart.html',
            url: '/my-cart?purchase',           
            controller: 'CartController'
        });

And then:

$state.go('cart', {'purchase': 'complete'});

The results will be:

my-cart?purchase=complete

Upvotes: 1

Saqueib
Saqueib

Reputation: 3520

try this

$state.go('cart', {'purchase': 'complete'});

Upvotes: 0

Related Questions