I got simple form like:
<form [formGroup]="registrationForm" (ngSubmit)="onSubmit()">
<label>Adres</label>
<input type="text" formControlName="address" class="form-control"
[ngClass]="{ 'is-invalid': submitted && f.address.errors }" />
<div *ngIf="submitted && f.address.errors" class="invalid-feedback">
<div *ngIf="f.address.errors.required">Address is required</div>
</div>
<input type="file" name="image" ng2FileSelect [uploader]="uploader"
accept="image/x-png,image/gif,image/jpeg" />
<button class="btn btn-primary mr-1 btn-block" [disabled]="!uploader.getNotUploadedItems().length">Send</button>
</form>
and there is my .ts onSubmit()
onSubmit() {
this.submitted = true;
if (this.registrationForm.invalid) {
return
}
this.accidentFormService.saveAccidentForm(this.registrationForm.value).subscribe(
res => {
console.log(res);
},
err => console.error(err)
);
// alert(JSON.stringify(this.registrationForm.value));
}
When code is outside form tag and button got (click)="uploader.uploadAll()"
it works fine but when it is inside form tag it doesn't works.
How can I send form and file at the same time? I got two other api routes for Form and File.