I want to disable button form during submit when the form is send to the server. So far this is the solution that I found:
clear() {
this.count++
this.formGroup.get('name').reset(null);
..........
if (this.count === 2) {
this.count = 1;
document.querySelector('.create-btn').setAttribute('disabled', '');
}
}
isDisabled() {
document.querySelector('.create-btn').removeAttribute("disabled");
}
HTML code:
<form [formGroup]="formGroup" (ngSubmit)="submit()" >
<div class="form-group" [ngClass]="errorClasses('name')">
<label>Name</label>
<input type="text" class="form-control name" formControlName="name" (click)="isDisabled()">
<div class="help-block form-text with-errors form-control-feedback" *ngIf="controlHasErrors('name')">
{{controlValidateMessage('name')}}
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<button type="button" class="btn btn-block"
[ngClass]="{'btn-success': formGroup.get('enabled').value, 'btn-light': !formGroup.get('enabled').value}"
(click)="selectTnx('enabled')">
<i class="fa fa-check mr-2"*ngIf="formGroup.get('enabled').value"></i>Enabled
</button>
</div>
</div>
</div>
</form>
Is there some other way to disable the submit button when the form is submitted?