我有问题。
我有服务DataStorageServiceService
,在此服务中,我有2种方法,deleteCategory
和deleteProduct
。我想从他的组件AdminComponent
中删除服务器上的产品和类别。我服务器上的结构是:
{
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' }
]
}
我的删除deleteCategory
方法可以正常工作,但是我的deleteProduct
现在可以很好地工作,并且不删除服务器上的产品。
这是我的deleteCategory
方法:
deleteCategory(product: CategoryModel | number): Observable<CategoryModel> {
const id = typeof product === 'number' ? product : product.id;
const url = `${this.cateogryUrl}/${id}`;
return this.http.delete<CategoryModel>(url, httpOptions).pipe(
catchError(this.handleError<CategoryModel>('deleteProduct'))
);
}
这是我的deleteProduct
方法:
deleteProduct(product: ProductModel | number, index:number): Observable<ProductModel> {
const idCategory = typeof product === 'number' ? product : product.id;
const id = index;
const url = `${this.cateogryUrl}/${id}/${idCategory}`;
return this.http.delete<ProductModel>(url, httpOptions).pipe(
catchError(this.handleError<ProductModel>('deleteProduct'))
);
}
我删除组件的方法是:
deteleProduct(indexCategory: number, indexProduct: number, category: ProductModel) {
this.dataStorageServiceService.deleteProduct(category,indexProduct).subscribe()
this.categoryList[indexCategory].products.splice(indexProduct, 1);
}
deteleCategory(indexProduct: number, category: CategoryModel) {
this.dataStorageServiceService.deleteCategory(category).subscribe();
this.categoryList.splice(indexProduct, 1);
}
有人知道为什么我不能删除服务器上的产品