在将用户数据添加到json之后,Angular http post添加了多个空对象

问题描述 投票:0回答:1

enter image description here.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个回答
2
投票
addProduct(productForm:NgForm){
    this.productService.addProduct(productForm.value).subscribe((res:any)=>
        res= **this.addProduct(res)**
    );  
}

你有一个不需要的递归。

© www.soinside.com 2019 - 2024. All rights reserved.