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

Export buildUrl in the global angular namespace #3213

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -1140,3 +1140,21 @@ function getter(obj, path, bindFnToScope) {
}
return obj;
}

function buildUrl(url, params) {
if (!params) return url;
var parts = [];
forEachSorted(params, function(value, key) {
if (value == null || value == undefined) return;
if (!isArray(value)) value = [value];

forEach(value, function(v) {
if (isObject(v)) {
v = toJson(v);
}
parts.push(encodeUriQuery(key) + '=' +
encodeUriQuery(v));
});
});
return url + ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&');
}
1 change: 1 addition & 0 deletions src/AngularPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var version = {
function publishExternalAPI(angular){
extend(angular, {
'bootstrap': bootstrap,
'buildUrl' : buildUrl,
'copy': copy,
'extend': extend,
'equals': equals,
Expand Down
21 changes: 0 additions & 21 deletions src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,26 +997,5 @@ function $HttpProvider() {
if (idx !== -1) $http.pendingRequests.splice(idx, 1);
}
}


function buildUrl(url, params) {
if (!params) return url;
var parts = [];
forEachSorted(params, function(value, key) {
if (value == null || value == undefined) return;
if (!isArray(value)) value = [value];

forEach(value, function(v) {
if (isObject(v)) {
v = toJson(v);
}
parts.push(encodeUriQuery(key) + '=' +
encodeUriQuery(v));
});
});
return url + ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&');
}


}];
}