Search code examples
javascriptangularjsangularjs-ng-href

Passing $location.search parameters using ng-href


Something really weird happens in my current code.

So I'm using ng-repeat to create several elements based on an array of objects like this:

<a ng-repeat="report in reports" ng-href="#/report?report={{report.id}}+file=0" ></a>

My rendered HTML looks as far as I can tell correctly like this:

<a ng-repeat="report in reports" ng-href="#/report?report=81+file=0" 
class="ng-scope" href="#/report?report=81+file=0">

If I now click on this link I am redirected to a url like this:

[root-url]/index.php#/report?report=84%20file%3D0

When I actually of course want to be here:

[root-url]/index.php#/report?report=84+file=0

Why is the "+" and the second "=" sign translated this way, when it is correct in the links-href-attribute? Anybody had this same problem? Any idea what I am doing wrong?


Solution

  • It is being URL encoded. It still has the same value.

    Currently, you only have one parameter keyed report with a value of 84 file=0. The plus sign in this case means a space.

    I'm assuming you wanted to have two parameters: report and file. To split parameters in a URL you have to use the ampersand symbol (&) instead of the plus sign.

    <a ng-repeat="report in reports" ng-href="#/report?report={{report.id}}&file=0" ></a>