这是我用于表单初始化的代码,我希望每次将读取值转换为数字后再通过验证
this.meterForm = this.formBuilder.group({
'reading': [newReading, this.getValidator(this.meter)],
'date': [this.date],
'time': [this.time],
'comments': [comments]
});
public getValidator(aMeter: Meter): ValidatorFn {
if (this.meter.type === this.generalInfo.meterTypes.counter) {
// I want to change the 'reading' input text field which is a string to number
return Validators.compose([
Validators.required,
WorkorderValidators.maxLength(18),
WorkorderValidators.max(this.meter.maxValue),
WorkorderValidators.min(this.meter.minValue),
WorkorderValidators.increment(0.0001, this.meter.minValue),
WorkorderValidators.precision(3)
]);
} else {
return Validators.compose([
Validators.required,
this.meterReadingValueValidation(18, 3)
]);
}
}