angularjs – 如何创建一个Angular.js $resource / $http工厂服
发布时间:2020-12-17 17:55:34 所属栏目:安全 来源:网络整理
导读:如何创建工厂$resource或$http服务来处理来自外部资源的具有多个任意参数的查询字符串? 例如. #/animals#/animals?gender=m#/animals?color=black#/animals?size=small#/animals?gender=mcolor=black#/animals?size=medgender=f#/animals?size=lggender=mco
如何创建工厂$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 该想法是存在按钮/输入,用户可以按下该按钮/输入以添加到查询字符串中的当前参数列表以获得具有不同组合的期望属性的新动物列表. angular.module(Animals,['$resource','$route','$location',function($resource,$route,$location) { return $resource('http://thezoo.com/animals',$route.current.params,{ query: {method: 'GET',isArray: true}}); }]); 谢谢 :) 解决方法
如果在调用资源时传入的参数与URL中指定的任何占位符都不匹配,则它们会自动转换为查询字符串参数.所以你应该这样做:
angular.module(Animals,isArray: true}}); }]); 然后当你尝试使用它时,你可以这样做: Animals.query({size:"med",gender:'f'}); 它会被翻译成: http://thezoo.com/animals?size=med&gender=f (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |