如何使用AngularJS $ http.delete发送数组类型参数?

时间:2017-12-22 12:12:52

标签: angularjs

如何使用AngularJS $ http.delete

发送数组类型参数
// notificationIds is array of ids.
deleteNotification(notificationIds) {
   let query = `/notifications`
   let params = {}
   notificationIds.forEach((id, index) => {
     params[`notificationIds[${index}]`] = id
   })
   return $http.delete(`wis`, query, params)
      .then((response) => response)
}

==>但结果是:(错误请求!!)

请求方法:DELETE

状态代码:400错误请求

1 个答案:

答案 0 :(得分:0)

  

我要感谢你们:)。这是正确的答案

deleteNotification(notificationIds) {
    let query = `/notifications`
    let data = ''
    notificationIds.forEach((id, index) => {
      data.length > 0 ? data += '&' : data += ''
      data += `notificationIds[${index}]=${id}`
    })
    const config = {
      data: data,
      headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' }
    }
    return this.ApiService
      .delete(`wis`, query, config)
      .then((response) => response)
  }