如何创建工厂$ resource或$ http服务来处理来自外部资源的具有多个任意参数的查询字符串?例如.
#/animals
#/animals?gender=m
#/animals?color=black
#/animals?size=small
#/animals?gender=m&color=black
#/animals?size=med&gender=f
#/animals?size=lg&gender=m&color=red
Run Code Online (Sandbox Code Playgroud)
该想法是存在按钮/输入,用户可以按下该按钮/输入以添加到查询字符串中的当前参数列表以获得具有不同组合的期望属性的新动物列表.我已经尝试了以下但它没有根据需要重新加载或添加新参数到现有的URL.另外,我不确定是否应该在控制器或工厂中调用$ route.current.params,如果这是最好的方法.
angular.module(Animals, ['$resource', '$route', '$location', function($resource, $route, $location) {
return $resource('http://thezoo.com/animals', $route.current.params, { query: {method: 'GET', isArray: true}});
}]);
Run Code Online (Sandbox Code Playgroud)
谢谢 :)