Skip to content

Instantly share code, notes, and snippets.

@jwgmeligmeyling
Created November 22, 2015 23:17
Show Gist options
  • Save jwgmeligmeyling/82028c293726a83b0ed2 to your computer and use it in GitHub Desktop.
Save jwgmeligmeyling/82028c293726a83b0ed2 to your computer and use it in GitHub Desktop.
Location search parameters for Angular
/**
* Angular Module that exposes the search parameters for the current window location.
* For example: http://localhost/?test=1
* Exposes: $searchParams.test === 5
* This is different than the search method in the $location service, which only exposes search params set in the location hash.
*
*/
angular.module('org.searchparams').service('$searchParams', function() {
window.location.search.substring(1)
.split("&")
.map(function(a) { return a.split("="); })
.reduce(function(obj, val) { obj[val[0]] = val[1]; return obj; }, this)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment