假设我有一个RESTful端点,它接受一系列方面来查询数据。这里有几个例子:
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
我的模块接受query对象来执行搜索:
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;
});
}
这些方面以web形式通过本地模型传递:
<input type="text" ng-model="query.location"/>
<input type="text" ng-model="query.radius"/>
<button type="button" ng-click="getSearch(query)">Search</button>
在getResults
函数的成功回调中,我尝试将查询参数附加到URL中,如上面的示例所示:
$scope.getSearch = function(query){
var search = $search.search(query);
search.getResults(function(results){
$scope.results = results;
search.appendQueryToURL(query);
});
}
如何在AngularJS中动态追加URL参数?
https://stackoverflow.com/questions/17491054
复制相似问题