我想在引導警報中顯示錯誤消息。我使用angular2作爲我的前端和流明作爲我的後端。Angular2如何顯示來自後端的錯誤消息
前端
<div class="alert alert-danger">
// Display error message here
</div>
我想從驗證功能的前端
public function uploadImage(Request $request)
{
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:60000',
]);
}
component.ts
uploadFile(): void {
let file = this.fileInput.nativeElement;
if (file.files && file.files[0]) {
let fileToUpload = file.files[0];
this.getInfoService
.uploadImage(fileToUpload)
.subscribe(
data => console.log("DATA", data),
err => console.log(err),
() => console.log("()",'yay')
);
}
在我的服務}
顯示響應
uploadImage(fileToUpload: any) {
let input = new FormData();
input.append("image", fileToUpload);
return this.http.post('http://Api.app/api/v1/uploadImage', input)
.map(
(response: Response) => {
console.log("Upload img service", response);
}
);
}
響應
您是否閱讀過關於處理可疑事件的錯誤? – jonrsharpe