0

I am working on an angular project where I have to make form in multiple steps, problem arises when I upload file in input field on particular step. If I move to any other step and come back I get the error : " Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string. "

My html file:-

<div *ngIf="step==1" [formGroup]="myForm">
    <input type="file" name="inp" id="inp" formControlName="inp">
</div>
<div *ngIf="step==2"></div>
<button (click)="change()">Change step</button>
{{myForm.value | json}}

My .ts file:-

export class AppComponent implements OnInit {
 myForm;
  constructor(private fb: FormBuilder) { }
  ngOnInit(): void {
    this.myForm = this.fb.group({
      inp: this.fb.control('')
    });


  }
  step = 1;
  change() {
    if (this.step == 1) {
      this.step = 2;
    } else {
      this.step = 1;
    }
  }
}
MoxxiManagarm
  • 8,735
  • 3
  • 14
  • 43
  • Try to have a look on this topic: https://stackoverflow.com/questions/41889384/angular2-validation-for-input-type-file-wont-trigger-when-changing-the-fi/41938495#41938495 – JStw Oct 10 '22 at 10:58

0 Answers0