Make edit images work
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, ElementRef, ViewChild } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
@@ -13,6 +13,7 @@ import { Product } from 'app/models/Product';
|
||||
imports: [ FormsModule, CommonModule ]
|
||||
})
|
||||
export class EditItemComponent {
|
||||
@ViewChild('FileUpload') InputDOM!: ElementRef<HTMLInputElement>;
|
||||
|
||||
readonly maxFileMB = 16;
|
||||
|
||||
@@ -45,6 +46,7 @@ export class EditItemComponent {
|
||||
http.get("api/productimage/get?ProductID=" + img.productID + "&ImageID=" + img.imageID, { responseType: 'blob' }).subscribe(blob => {
|
||||
img.imageSrc = URL.createObjectURL(blob);
|
||||
this.imagePreviews.push(img.imageSrc);
|
||||
this.selectedFiles.push(new File([blob], "EmptyName", {type: "image/jpeg"}));
|
||||
});
|
||||
});
|
||||
},
|
||||
@@ -62,8 +64,6 @@ export class EditItemComponent {
|
||||
imagePreviews: string[] = [];
|
||||
onFileSelected(event: Event){
|
||||
const fileInput = event.target as HTMLInputElement;
|
||||
this.imagePreviews = [];
|
||||
this.selectedFiles = [];
|
||||
|
||||
if (!fileInput.files?.length){
|
||||
return;
|
||||
@@ -83,13 +83,19 @@ export class EditItemComponent {
|
||||
this.imagePreviews.push(reader.result as string);
|
||||
}
|
||||
reader.readAsDataURL(file);
|
||||
|
||||
this.InputDOM.nativeElement.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
RemovePhoto(imagePreview: string){
|
||||
let i = this.imagePreviews.indexOf(imagePreview);
|
||||
this.imagePreviews.splice(i, 1);
|
||||
this.selectedFiles.splice(i, 1);
|
||||
}
|
||||
|
||||
onSubmit(){
|
||||
|
||||
const formData = new FormData();
|
||||
|
||||
// Append non-file fields
|
||||
formData.append("Name", this.newItem.name);
|
||||
formData.append("Description", this.newItem.description);
|
||||
|
||||
Reference in New Issue
Block a user