小编lin*_*hny的帖子

如何将数组数据作为 formdata angular 4 发送

我试图发布一组未发送到服务器的数据:

网络服务:

 deleteCategory() {
    return  this.http.post('http://www.demo/webapi/deletecategory', { 
        headers: {
          "Authorization": "Token " + this.token,
          "Content-Type": "application/x-www-form-urlencoded"
        },
        withCredentials: true
      }
      )
    }
Run Code Online (Sandbox Code Playgroud)

在 ts 文件中

onDelete() {
      this.userService.deleteCategory().subscribe(response => {
      this.selectedArray = [];
     for (var i = 0; i< this.selection._selected.length; i++){
     this.selectedArray.push(this.selection._selected[i].category_id) ;
     console.log(' selected value:', this.selectedArray);

     }
    })
      }
Run Code Online (Sandbox Code Playgroud)

在 html 中

<button class="btn-danger pull-right" (click)="onDelete()" type="button"  >Delete</button>
Run Code Online (Sandbox Code Playgroud)

http-post angular-http angular

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

angular-http ×1

http-post ×1