Let's say I have a RESTful endpoint that accepts a range of facets to query data. Here's a few examples:
example.com/search?type=Doctor&location=Boston,MA&radius=2
example.com/search?type=Facility&location=Wayne,NJ&radius=3&gender=f
example.com/search?type=Doctor&location=Patterson,NJ
My module accepts the query object to perform the search:
console.log(query);
{
type:'Doctor',
location:'Boston,MA',
radius:'2'
}
$scope.getSearch = function(query){
var search = $search.search(query);
search.getResults(function(results){
$scope.results = results;
});
}
These facets are being passed through a local model in a web form:
<input type=text ng-model=query.location/>
<input type=text ng-model=query.radius/>
<button type=button ng-click=getSearch(query)>Search</button>
In the success callback of the getResults
function, I'm trying to append the query parameters to the URL like in the examples above:
$scope.getSearch = function(query){
var search = $search.search(query);
search.getResults(function(results){
$scope.results = results;
search.appendQueryToURL(query);
});
}
How do I append URL parameters dynamically in AngularJS?