-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with setValue on FileInput control #9
Comments
Hi Amunds, You should try: this.formDoc.get('photo').patchValue( new FileInput([reader.result]) ); Let me know if this solves your issue. Bonus tip: you can try using fromEvent() observable to read data from you File/Blob (not tested) readFile(file: File | Blob): Observable<any> {
const reader = new FileReader();
loadend = fromEvent(reader, 'loadend').pipe(
map((read: any) => {
return read.target.result;
})
);
reader.readAsDataURL(file);
return loadend;
}
// then
readFile(file).subscribe(); |
I tried adding I'm now using the readFile function with the same issue. Please correct me if I'm wrong as I'm not proficient enough to debug this myself, but from my understanding FileInput only accepts File and not Blob. So when I overwrite the value of with a blob it causes errors because it can't find fileName and fileSize etc. So if I want to save a base64 blob to the database I'd instead want to populate a hidden field instead of trying to set the value on the , correct? |
Can you manage to set up a stackblitz demo of your issue. You can fork this: https://stackblitz.com/edit/ngx-material-file-input |
Here's the stackblitz: https://ngx-material-file-input-v3a7ij.stackblitz.io |
Ok, this seems to be related to template driven forms. I'll add to my todo list |
closing as of version 0.3.0 |
I'm doing a onChange:
<ngx-mat-file-input (change)="onFileChange(formDoc.value)">
This results in the following error in console:
The error happens as soon as onFileChange is called and continues forever as long as you're on the page.
There is also an error with the validator:
ERROR TypeError: Cannot read property 'map' of undefined at file-validator.ts:15 at forms.js:461 at Array.map (<anonymous>) at _executeValidators (forms.js:461) at forms.js:434 at forms.js:461 at Array.map (<anonymous>) at _executeValidators (forms.js:461) at FormControl.validator (forms.js:434) at FormControl.push.../../node_modules/@angular/forms/fesm5/forms.js.AbstractControl._runValidator (forms.js:2228)
The code does what it's supposed to do though, so it's not breaking anything as far as I can tell. Tested with the demo app and the same happens there.
The text was updated successfully, but these errors were encountered: