In an Angular application I have a form filters (multi select directive). Whenever a filter value is selected, it has to be included in the URL.
The goal is to be able to copy the URL with the form parameters and values and being able to send it to another client.
In this way the second client would open the same page and all its fields would be already filled with the same values used by the first client.
At the moment every value selection triggers a function that encodes the parameter and the relative value and adds it to the current URL.
function obj_to_query(obj) {
var parts = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
for (var i = 0; i < obj[key].Keys.length; i++) {
if (encodeURIComponent(obj[key].FilterType) == 1) {
parts.push(encodeURIComponent("areas=" + obj[key].Keys[i]));
}
else if (encodeURIComponent(obj[key].FilterType) == 2) {
parts.push(encodeURIComponent("categories=" + obj[key].Keys[i]));
}
}
}
}
return "?" + parts.join('&');
}
Is there a better way to achieve the same result?