我有一个laravel后端,我想在我的前端显示成功消息 下面是我的BackEnd控制器和角度2的前端。我怎样才能显示成功消息?
//后端
public function delete($id)
{
$food = food::all()->where('id', $id)->find($id);
if(is_null($food)){
return response()->json([
'msg' => 'Dish could not be found',
'retry' => true
], 404);
}
elseif($food->delete()){
return response()->json([
'msg' => 'Dish successfully deleted',
'retry' => false
], 202);
}
else
return response()->json([
'msg' => 'An error occured ',
'retry' => true
], 404);
}
}
//存放菜肴
$food->name = $request->name;
$food->location = $request->location;
$food->type = $request->type;
$food->save();
return 'Dish Record successfully added '
//前端
<div class="form-group">
<form (ngSubmit)="onSubmit(f)" #f="ngForm" >
<div class="form-group">
<label for="name"> Name</label>
<input type="text" class="form-control" id="name" [(ngModel)]="food.name" name="name" required>
</div>
<div class="form-group">
<label for="location">location</label>
<input type="text" class="form-control" id="location" [(ngModel)]="food.location" name="location" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="submit" class="btn btn-danger ">Cancel</button>
</div>
// api调用删除
deleteFood(id) {
return this.http.delete('http://example.com ' + id)
.map((response:Response) => response.json())
}