【问题标题】:angular 2 http delete parameter url appended with [object%20Object]附加 [object%20Object] 的 angular 2 http 删除参数 url
【发布时间】:2017-11-27 11:12:13
【问题描述】:

我在 angular 2 中使用 http.delete。这是我的代码

app.component.ts

deleteCourse(id: string)  {
       console.log(id);
       this.appService.deleteByID(id)

       .subscribe(x => {console.log(x); this.fetchCourseData(); }

        );
   }

app.service.ts

deleteByID(id: string): Observable<string> 

    let options1 = new RequestOptions();
    options1.headers = new Headers();
    options1.headers.append('Content-Type', 'application/json');
   return this.http.delete('http://localhost:3000/sample'+ '/' + id , options1)
     .map((response: Response) => {
            const result = response.json();
            return result; });
}

db.json

{
  "sample": [
    {

    {
      "courseTitle": "ggg",
      "courseDescription": "ggg",
      "courseCredit": "2",
      "id": 8
    },
    {
      "courseTitle": "ggg",
      "courseDescription": "ggg",
      "courseCredit": "1",
      "id": 9
    },
    {
      "courseTitle": "add",
      "courseDescription": "asdas",
      "courseCredit": "2",
      "id": 10
    }
  ]
}

url 传递为 http://localhost:3000/sample/[object%20Object]

还有 404 错误。我该如何纠正这个问题?

【问题讨论】:

    标签: json angular rest http http-status-code-404


    【解决方案1】:

    再次检查 deleteCourse 中的 console.log 是否打印出字符串值。我设法重现您的问题是通过将对象作为参数传递给 deleteCourse

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 2013-01-03
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      • 2018-08-29
      • 2020-09-13
      相关资源
      最近更新 更多