How to detect change in only query string parameters with AngularJS Route?

Issue

I wanted to work with query string parameters along with the usual route parameters in an AngularJS application and have been following the solution in this post: how to pass querystring in angular routes?

The solution seems to work: Change the route first with $location.path and then apply the query string parameters with $location.search.

However, I came across a scenario where the route does not need to change but the query parameters need to.

For example:

Moving from
‘/Books/Programming?id=123’
to
‘/Books/Mathematics?id=234’
works fine.

However,

Moving from
‘Books/Programming?id=123’
to
‘Books/Programming?id=124’
does not work.

It seems that AngularJS is only notified for changes on the regular route parameters and not for changes in the query string parameters so if query string is the only thing that changes in the URL, the application does not respond to the navigation.

Solution

As verified with AngularJS 1.6.5, and according to the Plunkr by @JB-Nizet, the problem does not occur anymore. The question still remains for what I missed earlier that it did not work.

Marking it as resolved as it does not occur anymore.

Answered By – myTerminal

Answer Checked By – Marilyn (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.