我使用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' }
]
}
我不能出错,但是不能更改服务器上的值。