Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
80
rated 0 times [  82] [ 2]  / answers: 1 / hits: 31022  / 11 Years ago, mon, march 4, 2013, 12:00:00

In Angularjs app, i have a url like
http://url.com/my_app/#/store/items.

Now i want to append query string for example,
http://url.com/my_app/#/store/items?page=2.

but in url, javascript encodes the ? to %3F which i don't want. It should remain ? only in the url as angularjs $location.search() returns nothing for %3F.


How it can be done ?


More From » angularjs

 Answers
97

There is not enough details in your question so I will assume that you are using AngularJS routing - or at least the $location service - in non-HTML5 mode. If so, the part after the # character represents your URL from the single-page-application point of view (more about AngularJS here).



If the above assumptions are correct it means that you shouldn't try to add or manipulate the question mark by hand. Instead you should change the search part of the $location to manipulate query string (part after ?) and the question mark will be added / removed to the final URL as needed.



In your case you could write:



$location.path('/store/items').search('page', 2)


This is assuming that you are manipulating URLs from JavaScript, as stated in your question.


[#79858] Saturday, March 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
farrahsavannahl

Total Points: 418
Total Questions: 108
Total Answers: 90

Location: Bonaire
Member since Sat, May 1, 2021
3 Years ago
;