Last active
December 30, 2015 19:09
-
-
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}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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