Hi
In below code i am getting error
uploadImage(event:any){
debugger;
const file = event.currentTarget.files[0];
if(event.target.files.length > 0 ){
if(file.type == 'image/png' || file.type == 'image/jpeg') {
const formObj = new FormData();
formObj.append('file',file);
this.post('storeapi.gerasim.in/Customer/Upload',formObj).subscribe((res: any)=>{
this.uploadedFileNames.push(res);
});
}
}
}
Thanks
Jayraj ChhayaPosted May 30, 2024, 6:53 AM
Hi Ramco,
If you are using Angular 17, then
*ngFordirective has been replaced with the@fordirective for iterating over arrays.Angular 17
Ramco RamcoPosted May 30, 2024, 6:05 AM
Hi Jayraj
If i want to use @for (item of uploadedFileNames) then what i need to change
Thanks
Jayraj ChhayaPosted May 30, 2024, 5:51 AM
Problem
The code has a bug that causes an error: "Property file does not exist on type 'Advance Component'". This error occurs because the variable
fileis not declared within the scope of the loop in the image display section.Reason
The issue arises from attempting to access the
filevariable within the loop@for (item of uploadedFileNames). Thefilevariable is defined within theuploadImagefunction but is being referenced outside its scope, leading to a TypeScript compilation error.Solution
To fix the bug and resolve the TypeScript error, we need to ensure that the
filevariable is accessible within the loop. One way to achieve this is by modifying the code structure to include thefilevariable in the loop's scope.By using the
*ngFordirective in Angular templates, we can iterate over theuploadedFileNamesarray and access thefilevariable within the loop's scope, resolving the TypeScript error.