Skip to content

Instantly share code, notes, and snippets.

@kennethlynne
Last active December 30, 2015 19:09
Show Gist options
  • Save kennethlynne/7872346 to your computer and use it in GitHub Desktop.
Save kennethlynne/7872346 to your computer and use it in GitHub Desktop.
Helper to transform a string with url parameters into a matching key-value object. ?thing=a&stuff=b will result in params being set to {thing:a,stuff:b}
urlParams = "?thing=a&stuff=b";
var params = {};
//Match anything that has a sequence of word characters an equalsign until next block denoted by ? or &
urlParams = urlParams.match(/[\w]+\=[^\?\&]+/g);
angular.forEach(urlParams, function (match) {
var data = match.split('=');
var key = data[0], value = data[1];
params[key]=value;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment