我正在使用angular6和laravel实现删除功能。但是在某个时候我被困住了
List.component.html
<button class="delete-wrap" (click)="deletelist(contact.id)">
List.component.ts
deletelist(id){
console.log(id);
this.Jarwis.deleteList(id).subscribe(res=>{
console.log(res);
});
在jarwis服务中
deleteList(id){
alert(id);
return this.http.post(`${this.baseUrl}/deleteList`,id)
}
我的laravel的api.php如下
Route::post('deleteList', 'AddListController@deleteList');
在AddListController中
public function deleteList($id)
{
echo $id;
}
当我尝试在AddListController的deleteList方法中回显ID时说
Too few arguments to function App\Http\Controllers\AddListController::deleteList(), 0 passed and exactly 1 expected
我正在获取ID,直到Jarwis服务的deleteList。我想念什么?
答案 0 :(得分:1)
据我所知,您需要在headerOptions中设置参数
this.http.post(`${this.baseUrl}/deleteList`, { params: { 'id': id} })
答案 1 :(得分:1)
您需要在路线中接受id
Route::post('deleteList/{id}', 'AddListController@deleteList');