如何定义在$资源的自定义操作的路径部分? [英] How to define a path section in custom actions of $resource?

查看:209
本文介绍了如何定义在$资源的自定义操作的路径部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以指定定制$资源操作的路径?

我想写点东西,如:

  angular.module('MyServices',['ngResource'])工厂('用户',['$资源',($资源) -  GT;
  $资源('/用户',{},{
    名称:{路径:'/名称,方法:GET,IsArray的:真正}
  })
])

所以我可以用它喜欢的:

  User.names()#GET /用户/名字


解决方案

这是不直接支持AngularJS的当前版本,但有一个的拉申请打开所以有机会,它会在不久的将来得到支持。

在那之前你有三种选择:

1)中的路径变量播放:

  $资源('/用户/:名',{},{
    名称:{params:一个{名称:'名'},方法:GET,IsArray的:真正}
  })

2)使用 $ HTTP服务,而不是

3)尝试自提公关code对AngularJS的猴子打补丁的版本

Is it possible to specify the path of a custom $resource action ?

I would like to write something like:

angular.module('MyServices', [ 'ngResource' ]).factory('User', [ '$resource', ($resource)->
  $resource('/users', {}, {
    names: { path: '/names', method: 'GET', isArray: true }
  })
])

So I can use it like:

User.names() # GET /users/names

解决方案

It is not directly supported in the current version of AngularJS but there is a pull request open so there is chance that it will be supported in the near future.

Till then you've got 3 options:

1) Play with variables in the path:

$resource('/users/:names', {}, {
    names: { params: {names: 'names'}, method: 'GET', isArray: true }
  })

2) Use the $http service instead

3) Try the code from the mentioned PR on the monkey-patched version of AngularJS

这篇关于如何定义在$资源的自定义操作的路径部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆