【问题标题】:Angular http post adds multiple empty objects after adding user data to jsonAngular http post在将用户数据添加到json后添加了多个空对象
【发布时间】:2018-09-18 15:29:40
【问题描述】:

.ts:

addProduct(productForm:NgForm){


  this.productService.addProduct(productForm.value).subscribe((res:any)=>
    res= this.addProduct(res)

  );

 }

.服务:

addProduct(productForm:NgForm) {

        return this.httpObj.post<products>(`${this.uri}/products`,productForm,{
            headers: new HttpHeaders({
                'Content-Type': 'application/json'
            })
    });

当我输入表单数据并提交时,最后输入的数据被覆盖并输入了新数据。新数据后,插入了多个空行。可能是什么问题?

【问题讨论】:

  • 嗯,可能是后端问题?进入网络选项卡,并截取您发送到服务器的有效负载。让我们看看它
  • 我已添加请检查

标签: angular http-post httpclient


【解决方案1】:
addProduct(productForm:NgForm){
    this.productService.addProduct(productForm.value).subscribe((res:any)=>
        res= **this.addProduct(res)**
    );  
}

您正在进行不需要的递归。

【讨论】:

  • 谢谢你..觉得有帮助
猜你喜欢
  • 2016-12-27
  • 2016-06-29
  • 2015-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-11
  • 2017-11-24
  • 1970-01-01
相关资源
最近更新 更多