I am having a ngform with file input along with other input fields. Currently I am passing data to the component using ngmodel on submit. But I don't know how to perform the file upload with ngmodel.In the backend I am using Laravel.
Currently I am able to get the file data in the component function handleFileInput.I want to pass this data along with other form input fields.How do I achieve that?
Template code
<div class="form-group">
<label for="file">Choose File</label>
<input type="file" id="file" (change)="handleFileInput($event.target.files)">
</div>
Component code
handleFileInput(files: FileList) {
this.fileToUpload = files.item(0);
}
onSubmit Method
onSubmit() {
this.loading = true;
this._dataService.create(this.model, company_url).subscribe(data => {
this.submitted = true;
this.loading = false;
this.companyForm.reset();
},
error => {
this.loading = false; console.log(error);
this.error_message = error;
});
}