I have an image upload input in my form:
<input type="file" [(ngModel)]="item.image" name="image" #image>
Is it possible to access #image.files[0]
using item.image
ngModel (instead of creating a reference)?
If not, what does ngModel stores anyway when the input type is file
?
Is it possible to access #image.files[0] using item.image ngModel (instead of creating a reference)?
Yes, you can subscribe to the change
event of the input and pass the file to the method:
<input type="file" name="image" (change)="fileSelected($event.target.files[0])" />
What does ngModel stores anyway when the input type is file?
Nothing. DefaultValueAccessor does not work with input[type="file"]
and I don't think there is a specific value accessor for it at the moment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With