I am having the below code part.
ngOnInit(): void {
this.form = this.formBuilder.group({
apiCodesFile: ['']
});
}
public onFileSelect(event) {
if (event.target.files.length > 0) {
this.isFileSelected = true;
const file = event.target.files[0];
this.form.get('apiCodesFile').setValue(file);
} else {
this.isFileSelected = false;
}
}
But I need to use get/set methods to set the form value for the formControl 'apiCodesFile' rather than setting it inside 'onFileSelect' method.
I added the below code parts. But it gave an error.
set apiCodesFile (val) {
this.form.get('apiCodesFile').setValue(val);
}
public onFileSelect(event) {
if (event.target.files.length > 0) {
this.isFileSelected = true;
const file = event.target.files[0];
this.apiCodesFile(file);
} else {
this.isFileSelected = false;
}
}
Error:
ERROR TypeError: this.apiCodesFile is not a function
Please give me a solution for this.
this.apiCodesFile = "value"to set value.