テーブルからオブジェクトを削除しようとしていますが、コンポーネントにパラメータとして渡していますが、最終的にバックエンドの呼び出し時にID常にnullです。角2 - IDによる削除メソッドが動作しない
私のHTMLコードは次のようになります。
<tr *ngFor="let articulo of articulos | nombre: nombreText | familia: familiaText | codigo: codigoText | paginate: {itemsPerPage: 15, currentPage:page, id: '1' };">
<td>{{articulo.codigo}}</td>
<td>{{articulo.proveedor}}</td>
<td>{{articulo.nombre}}</td>
<td>{{articulo.familia}}</td>
<td>{{articulo.precio}}</td>
<td>{{articulo.fechaModificacion}}</td>
<td>{{articulo.anotaciones}}</td>
<td>
<div class="btn-group btn-group-sm pull-right" >
<button class="btn btn-xs pink whiteFont" title="Editar artículo">
<i class="fa fa-pencil" aria-hidden="true"></i>
</button>
<button (click)="deleteArticulo(articulo); $event.stopPropagation()" class="btn btn-xs pink whiteFont" title="Eliminar artículo">
<i class="fa fa-trash-o" aria-hidden="true"></i>
</button>
</div>
</td>
</tr>
ArticulosComponent.tsはメソッドの削除:
delete(id: number) {
const url = `${this.articulosURL}/${id}`;
return this.http.delete(url, { headers: this.headers }).map(() => null);
}
そして最後に、私:ArticulosService.tsは、メソッドを削除
deleteArticulo(articulo: Articulo): void {
this.articulosService.delete(articulo.id).subscribe();
}
をJavaコントローラ:
@DeleteMapping("/articulos/{id}")
public ResponseEntity<Void> deleteArticulo(Integer id){
try {
articulosService.delete(id);
return new ResponseEntity<Void>(HttpStatus.OK);
} catch(Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
これについてのヒントはありがたいです。ありがとうございました!
PS:私の英語、イムないネイティブスピーカーのために申し訳ありません
URLの代わりに体にIDを渡すようにしてください。 –
それが可能であるかどうかわからなかった、できるだけ早く私がそれをチェックする。前もって感謝します。 –