Created
November 22, 2015 23:17
-
-
Save jwgmeligmeyling/82028c293726a83b0ed2 to your computer and use it in GitHub Desktop.
Location search parameters for Angular
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
/** | |
* 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