File Upload in Angular Form array

Viewed 280

I need to upload pdf file in Form array along with title.

I'm unable to add pdf file data in that form control.

On save I need to have title along with file data in their respective form controls.

Please help me out?

Thanks in advance!

Code available at Stackblitz click here

1 Answers

HTML part -

remove "formControlName"

<input type="file" (change)="upload($event,i)" accept=".pdf" class="form-control">

TS part -

upload(event: any, index: number): void {
    let fileName = event.target.files[0].name;
    this.docs.controls[index].patchValue({"file": fileName});
}
Related