I have a function that gets the file name.
This name is filled in an input, however the input background color is visible only when I insert a file and the file name information is filled there.
I want the background color to be visible when it has or doesn't have values.
It had this:
<input * ngIf = "items.length> 0" type = "text" [(ngModel)] = "items [0] .filename" class = "form-control Input-Metadata">
I want this:
<input * ngIf = "items.length>= 0" type = "text" [(ngModel)] = "items [0] .filename" class = "form-control Input-Metadata">
When using this I get the following error: Cannot read property 'filename' of undefined.
Can anyone help me?
component.ts
for (let index = 0; index < files.length; index++) {
const item: any = {
filename: event.target.files[index].name.split('.')[0],
fileType: event.target.files[index].type.split("image/").join(""),
fileSize: event.target.files[index].size,
};
this.filename = item.filename;
this.fileType = item.fileType;
this.fileSize = item.fileSize;
this.items.push(item);
const reader = new FileReader();
reader.onload = (e: any) => {
item.url = e.target.result;
const image = new Image();
image.src = e.target.result;
image.onload = function () {
item.sizeH = image.width;
item.sizeV = image.height;
self.sizeH = item.sizeH;
self.sizeV = item.sizeV;
};
}
formData.append('file', files[index]);
reader.readAsDataURL(files[index]);
}