简体   繁体   English

URL参数作为Angular Resource的主体参数传递

[英]URL param passed as body param with Angular Resource

I am using Angular (1) with $resource . 我正在将Angular(1)与$resource One of my API request is failing because a URL param is passed as a request body param instead. 我的API请求之一失败,因为URL参数被作为请求正文参数传递。 Why is this happening? 为什么会这样呢?

/** @ngInject */
module.exports = function ($resource, API_URL) {
  return $resource(`${API_URL}/users`, null, {
    deactivateUser: {
      url: `${API_URL}/users/deactivate/:id`,
      method: 'put'
    },
    ...
  })
}

Used here: 在这里使用:

User.deactivateUser({id})

According to the docs , you should specify {id: '@id'} as a second parameter to $resource function. 根据文档 ,您应该将{id: '@id'}指定为$resource函数的第二个参数。 For non-GET requests this will take id parameter and place it into url string, not request body. 对于非GET请求,它将使用id参数并将其放入url字符串,而不是请求正文中。

Here is the fiddle for that. 这是小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM