0

I'm getting callbacks (from singly.com) in the form or URLs like
example.com/path#p1=v1&p2=v2...

What would be the Angular way to extract the query parameters? $location.search and $routeParams don't seem to work, I'm guessing due to the lack of the ? in the URL.

Update: I have achieved my objective by manually attacking the URL via absUrl() but I'd like to know if there is a more Angular way of achieving the objective.

axzr
  • 660
  • 5
  • 16

1 Answers1

0

Ported from and based upon: https://stackoverflow.com/a/3855394/1250044

var queryHash = function (hash) {
    hash = (hash || location.hash).slice(1).split("&");
    var b = {};
    for (var i = 0; i < hash.length; ++i) {
        var p = hash[i].split("=");
        if (p.length !== 2) continue;
        b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
    }
    return b;
};

console.log( queryHash() );

http://fiddle.jshell.net/xTSaV/

Community
  • 1
  • 1
yckart
  • 32,460
  • 9
  • 122
  • 129
  • Thanks for your answer, but it isn't really answering how to do this 'the Angular way'. – axzr Jun 03 '13 at 13:00