Angular ui router change state with request parameters

How can I go to state and add query parameters to the url at the same time? Let's say I have this state:

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

      

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

+3


source to share


2 answers


So I found the answer, hope this helps 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

      

+1


source


try it



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

      

0


source







All Articles