--- ACTUALIZACION SOLUCION DE MI PARTE A MI PROBLEMA ----
public applyCupon(forma: NgForm) {
this.isValidatingCupon = true;
const cupons = this.discountCodeTags.map(tag => tag.code);
const currentCupon = this.discountCodeForm.codeControl.value;
if (!cupons.includes(currentCupon)) {
const params = {
coupon: this.discountCodeForm.codeControl.value
} as IDiscountCodeRequestParams;
this.discountCodeImplement.validateDiscountCode$(params)
.pipe(take(1))
.subscribe(response => {
if (response.valid) {
const couponInput = new Coupon ();
couponInput.barCode = this.discountCodeForm.codeControl.value;
couponInput.productName = this.discountCodeForm.codeControl.value;
this.addCoupons.push(couponInput);
this.guardarLocalStorage();
this.discountCodeForm.resetForm;
} else {
this.errorScheduleModalService.showErrorCouponModa(currentCupon);
}
this.discountCodeForm.codeControl.setValue('');
this.isValidatingCupon = false;
});
} else {
this.discountCodeForm.codeControl.setValue('');
}
if (forma.invalid) {
Object.values(forma.controls).forEach( control => {
control.markAllAsTouched();
})
}
}
<form
[formGroup]="discountCodeForm.form"
(ngSubmit)="applyCupon()"
[hidden]="discountCodeTags.length > 0"
class="block_codigo_descuento"
#forma
>
<div class="input_codigo_descuento">
<fp-input-control
[inputTitle]="''"
[errorMessage]="''"
[marginBottomZero]="true"
>
<input
type="text"
id="nameCupon"
class="input"
placeholder="Ej. 6W79H6"
formControlName="code"
[class.isinvalid]="!discountCodeForm.form.valid && discountCodeForm.form.touched"
/>
<small class="small" *ngIf="!discountCodeForm.form.valid && discountCodeForm.form.touched">
Código Inválido
</small>
</fp-input-control>
</div>
<div class="btn_agregar_codigo">
<button
type="submit"
id="applyCoupon"
class="btn btn-primary btn-aplicar"
[disabled]="!discountCodeForm.form.valid || isValidatingCupon"
>
Agregar
</button>
</div>
</form>