I am trying to build a form in Angular 6 that offers a file selection box that allows the user to select multiple files (Stackblitz: https://stackblitz.com/edit/angular-yjummp).
The Template looks like:
<form [formGroup]="form">
<input id="files" formControlName="files" type="file" accept="image/*,video/*" multiple (change)="onFilesChanged($event)"/>
</form>
I am building the form in TypeScript like this:
public form = new FormGroup({
files: new FormControl('')
});
public onFilesChanged(event: any): void {
console.log(event.target.files);
console.log(this.form.value);
}
Now, in the onFilesChanged Handler, the selected files can be correctly retrieved from the event by accessing event.target.files (obviously), but printing the form value only prints one file. I have been trying a number of ways using FormArray as well, but had no luck so far.
Any ideas? Many thanks!