Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f64afc7

Browse files
committed
Export buildUrl in the global angular namespace
buildUrl could be used outside of $http too, for example if the user needs to create urls for APIs that are not natively supported in angular (EventSource for ex.) potentionally if it's not hidden in a closure inside $http, it might be used in other parts of angular too
1 parent de4b048 commit f64afc7

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

src/Angular.js

+18
Original file line numberDiff line numberDiff line change
@@ -1140,3 +1140,21 @@ function getter(obj, path, bindFnToScope) {
11401140
}
11411141
return obj;
11421142
}
1143+
1144+
function buildUrl(url, params) {
1145+
if (!params) return url;
1146+
var parts = [];
1147+
forEachSorted(params, function(value, key) {
1148+
if (value == null || value == undefined) return;
1149+
if (!isArray(value)) value = [value];
1150+
1151+
forEach(value, function(v) {
1152+
if (isObject(v)) {
1153+
v = toJson(v);
1154+
}
1155+
parts.push(encodeUriQuery(key) + '=' +
1156+
encodeUriQuery(v));
1157+
});
1158+
});
1159+
return url + ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&');
1160+
}

src/AngularPublic.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var version = {
2525
function publishExternalAPI(angular){
2626
extend(angular, {
2727
'bootstrap': bootstrap,
28+
'buildUrl' : buildUrl,
2829
'copy': copy,
2930
'extend': extend,
3031
'equals': equals,

src/ng/http.js

-21
Original file line numberDiff line numberDiff line change
@@ -997,26 +997,5 @@ function $HttpProvider() {
997997
if (idx !== -1) $http.pendingRequests.splice(idx, 1);
998998
}
999999
}
1000-
1001-
1002-
function buildUrl(url, params) {
1003-
if (!params) return url;
1004-
var parts = [];
1005-
forEachSorted(params, function(value, key) {
1006-
if (value == null || value == undefined) return;
1007-
if (!isArray(value)) value = [value];
1008-
1009-
forEach(value, function(v) {
1010-
if (isObject(v)) {
1011-
v = toJson(v);
1012-
}
1013-
parts.push(encodeUriQuery(key) + '=' +
1014-
encodeUriQuery(v));
1015-
});
1016-
});
1017-
return url + ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&');
1018-
}
1019-
1020-
10211000
}];
10221001
}

0 commit comments

Comments
 (0)