eeejay
eeejay

Reputation: 5854

How Get All State Params

I have a state like this:

$stateProvider.state('offers',{
    url: '/offers?{specialOfferCode}

If I navigate to a URL such as:

/offers?specialOfferCode=10&foo=bar

The $stateParams returned are

{ specialOfferCode : 10 }

That is, any additional parameters get stripped off. I cannot add more params to the defined state url because there could be a variable number of parameters and they could be named anything.

How can I get all my params in the $stateParams object, regardless of how many additional parameters there are? (That is, I have no way of knowing in advance what my parameters might be. All I know for certain is that there is a "specialOfferCode" parameter.)

Upvotes: 1

Views: 576

Answers (2)

tombarti
tombarti

Reputation: 426

Inject $location into your controller and then use $location.search(). This should return the following object:

Object {specialOfferCode : "10", foo: "bar"}

Upvotes: 2

Arno_Geismar
Arno_Geismar

Reputation: 2330

You need to include the stateparam in your route :

$stateProvider.state('offers',{
    url: '/offers?{specialOfferCode}&{foo}

Upvotes: 0

Related Questions