如何通过 SKU 而不是 ID 删除行?
How can I delete a row by its SKU instead of its ID?
我尝试删除使用产品 sku 的行。我正在使用 spring 引导和 angular。当我在我的按钮上添加 sku 时出现错误 (click)="onDeleteProductBySku(deleteClick?.sku)"
它说 Property 'sku' does not exist on type '(product: Product) => void'.
。在我的命令提示符下,我收到了这个错误。我该如何解决这个问题?
Error: product/product.component.html:50:109 - error TS2339: Property 'sku' does not exist on type '(product: Product) => void'.
50 <button class="btn btn-outline-danger btn-sm me-2" (click)="onDeleteProductBySku(deleteClick?.sku)">Delete</button>
product/product.component.ts:12:16
12 templateUrl: './product.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component ProductComponent.
ProductsController.java --> 这是邮递员的工作。
//Delete a product record using sku
//http://localhost:8080/products/deletebysku?sku=12345678
@DeleteMapping("/products/deletebysku")
@ResponseBody
private void deleteProductBySku(@RequestParam String sku){
productsService.deleteProductBySku(sku);
}
product.component.ts
public deleteProduct!: Product;
public onDeleteProductBySku(sku: string): void {
this.productServive.deleteProductBySku(sku).subscribe(
(response: void) => {
this.messageShow();
console.log(response);
this.getAllProduct();
},
(error: HttpErrorResponse) => {
this.errorMessage(error.message);
}
);
}
public deleteClick(product: Product) {
this.deleteProduct = product;
console.log("delete by sku");
}
product.service.ts
public deleteProductBySku(sku: string): Observable<void> {
return this.http.delete<void>(`${this.apiServerUrl}/products/deletebysku?sku=${sku}`);
}
product.component.html
<button class="btn btn-outline-danger btn-sm me-2" (click)="onDeleteProductBySku(deleteClick?.sku)">Delete</button>
你的deleteClick
是void类型的函数,它不return也不包含sku
属性。你不是想这样调用删除函数吗?
<button
class="btn btn-outline-danger btn-sm me-2"
(click)="onDeleteProductBySku(product?.sku)"
>
Delete
</button>
<!-- Or maybe?
(click)="onDeleteProductBySku(this.deleteProduct?.sku)"
-->
我尝试删除使用产品 sku 的行。我正在使用 spring 引导和 angular。当我在我的按钮上添加 sku 时出现错误 (click)="onDeleteProductBySku(deleteClick?.sku)"
它说 Property 'sku' does not exist on type '(product: Product) => void'.
。在我的命令提示符下,我收到了这个错误。我该如何解决这个问题?
Error: product/product.component.html:50:109 - error TS2339: Property 'sku' does not exist on type '(product: Product) => void'.
50 <button class="btn btn-outline-danger btn-sm me-2" (click)="onDeleteProductBySku(deleteClick?.sku)">Delete</button>
product/product.component.ts:12:16
12 templateUrl: './product.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component ProductComponent.
ProductsController.java --> 这是邮递员的工作。
//Delete a product record using sku
//http://localhost:8080/products/deletebysku?sku=12345678
@DeleteMapping("/products/deletebysku")
@ResponseBody
private void deleteProductBySku(@RequestParam String sku){
productsService.deleteProductBySku(sku);
}
product.component.ts
public deleteProduct!: Product;
public onDeleteProductBySku(sku: string): void {
this.productServive.deleteProductBySku(sku).subscribe(
(response: void) => {
this.messageShow();
console.log(response);
this.getAllProduct();
},
(error: HttpErrorResponse) => {
this.errorMessage(error.message);
}
);
}
public deleteClick(product: Product) {
this.deleteProduct = product;
console.log("delete by sku");
}
product.service.ts
public deleteProductBySku(sku: string): Observable<void> {
return this.http.delete<void>(`${this.apiServerUrl}/products/deletebysku?sku=${sku}`);
}
product.component.html
<button class="btn btn-outline-danger btn-sm me-2" (click)="onDeleteProductBySku(deleteClick?.sku)">Delete</button>
你的deleteClick
是void类型的函数,它不return也不包含sku
属性。你不是想这样调用删除函数吗?
<button
class="btn btn-outline-danger btn-sm me-2"
(click)="onDeleteProductBySku(product?.sku)"
>
Delete
</button>
<!-- Or maybe?
(click)="onDeleteProductBySku(this.deleteProduct?.sku)"
-->