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;
}
}
}