I have a reactive form like this
this.form = this.fb.group({
items: this.fb.array(
[
this.fb.group({
net_amount: [
null,
Validators.compose([
Validators.required,
Validators.pattern('^[0-9]+(.?[0-9]+)?$'),
isValidNumericValue
])
],
})
],
Validators.required
),
substances: this.initAdditives(),
net_total: [
this.currentProduct.net_total || null,
[
Validators.required,
Validators.pattern('^[0-9]+(.?[0-9]+)?$'),
isValidNumericValue
]
]
});
isValidNumericValue is a custom validator that checks whether a number is greater than zero. The problem is the validator works outside FormArray but not inside.
export function isValidNumericValue(AC: AbstractControl) {
if (AC.value <= 0) {
return { numericError: true };
}
return null;
}