Skip to content

Commit 1a560b9

Browse files
committed
Merge pull request saymedia#13 from kshay/master
Enhance the overriden $location service's search() method.
2 parents f896b39 + 580034a commit 1a560b9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/ngoverrides.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ function registerModule(context) {
103103
};
104104
};
105105
var parsedUrl = function (code) {
106-
return function (set) {
106+
return function (set, value) {
107107
if (request) {
108108
if (! requestUrlParts) {
109109
requestUrlParts = url.parse(request.url, true);
110110
}
111-
return code(requestUrlParts, set);
111+
return code(requestUrlParts, set, value);
112112
}
113113
else {
114114
throw new Error('location not available yet');
@@ -170,7 +170,19 @@ function registerModule(context) {
170170
}
171171
),
172172
search: parsedUrl(
173-
function (parts) {
173+
function (parts, set, paramValue) {
174+
if (set) {
175+
if (paramValue === null) {
176+
delete parts.query[paramValue];
177+
}
178+
else if (paramValue) {
179+
parts.query[set] = paramValue;
180+
}
181+
else {
182+
parts.query = set;
183+
}
184+
return this;
185+
}
174186
return parts.query;
175187
}
176188
),

0 commit comments

Comments
 (0)