$location changes the ? parameter delimiter
Asked Answered
K

1

9

I wan't to open the following url from my controller /plant/needs/temperatures?open=temperatures, where the parameter open=temperatures is there to ask the page to open the related popup with the code as follows:

$scope.openPageUrl = function (url) {
    closePopover();
    console.log("Open page url "+url);
    $location.path(url);
};

<a ng-click="openPageUrl('/plant/needs/temperatures?open=temperatures')">Click to open</a>

Unfortunately, I've got this url #/plant/needs/temperatures%3Fopen=temperatures requested, with the question mark replaced by %3F, preventing the page to open.

Any idea to fix this?

Kauppi answered 15/7, 2014 at 17:17 Comment(2)
Looks like the string gets encoded on the server side. What kind of server are you using?Somersault
try $location.path(decodeURIComponent(url));Joan
P
14

If you try to get the current path using $location.path it will return path without query strings because $location.path don't understand them. So that's why it encodes it when appending new path.

You should use $location.url which won't encode ?. Because it handles the changes of .path, .search and .hash

$location.url(url);
Pompadour answered 15/7, 2014 at 17:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.