我試圖從表中刪除一個對象,並將其作爲參數傳遞給組件,但是,當我最終向後端調用ID時的對象始終爲空。Angular 2 - 通過ID不起作用的HTTP刪除方法
我的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刪除方法:
deleteArticulo(articulo: Articulo): void {
this.articulosService.delete(articulo.id).subscribe();
}
的ArticulosService.ts刪除方法:
delete(id: number) {
const url = `${this.articulosURL}/${id}`;
return this.http.delete(url, { headers: this.headers }).map(() => null);
}
最後,我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:對不起,我的英語,我不是一個母語
嘗試通過ID在體內,而不是網址。 –
不知道這是可能的,我會檢查它,如果我儘快工作。提前致謝。 –