Angular 7中httpClient中的put方法问题

时间:2018-12-10 22:19:11

标签: angular typescript angular-in-memory-web-api

我使用in-memory-web-api。 我在DataStorageServiceService处放置了方法deleteProduct。 这是我的deleteProduct方法:

 deleteProduct(product: CategoryModel, index: number): Observable<any> {
    const idCategory = typeof product === 'number' ? product : product.id;
    const id = index;

   const url = `${this.cateogryUrl}/${id}`;

    return this.http.put(url, product, httpOptions).pipe(

      catchError(this.handleError<any>('deleteProduct'))
    );
  }

我有组件AdminComponent,这里有deteleProduct方法。 这是我的deteleProduct

 deteleProduct(indexCategory: number, category: CategoryModel) {
    this.dataStorageServiceService.deleteProduct(category,indexCategory).subscribe();
    this.categoryList[indexCategory].products.splice(indexProduct, 1);

  }

这是我要更改的json

{
                id: 1, name: 'Mr.', description: 'dasdad', image: "sada", products: [
                    { id: 0, name: 'Milos', description: "sdada", numberOfProduct: 1, image: 'ssad' },
                ]



            },
            {
                id: 2, name: 'Misko', description: 'dasdad', image: "sada", products: [
                    { id: 0, name: 'Milos', description: "sdada", numberOfProduct: 1, image: 'ssad' },
                    { id: 1, name: 'Somi', description: "haha", numberOfProduct: 1, image: 'haha' }
                ]
            }

我不能出错,但是不能更改服务器上的值。

0 个答案:

没有答案