Martin
Martin

Reputation: 24308

AngularJS: How to provide a search facility and cause route change passing in params?

I need to be able to offer a search facility that will show results, I suppose allowing this route to be be bookmarkable.

What are my options here?

Do I just need to create a new route and place a resolve on there so that i can call my rest service and only display the page when its ready. Then i presume I would force a change of route via my existing controller ?

Problem I see is that I need to store a number of items on the URL, all the search params otherwise it won't be bookmarkable. Is the only way to do this by passing ugly querystrings ?

And how would I access the querystrings from angularjs so i could extract my params that i need to send along to the rest service.

I have tried googling for something similar or an example but I can't seem to find anything.

Has anyone done something similar, any pointers would be really helpful.

thanks

Upvotes: 3

Views: 71

Answers (1)

Josh
Josh

Reputation: 44906

The $location service has a search method that acts as both a getter and a setter for querystring parameters.

It will return an object that corresponds to your parameters:

{
  foo:123,
  bar:'Kittens'
}

Upvotes: 2

Related Questions