使用角1.5如何控制Angular验证程序的评估顺序?
我明白,当指令被触发时角度验证器会被添加到字段中,然后当控件的值改变所有验证器的激活时。我有一个金额字段的3个不同的验证(正确的字符,最大长度,并且不能为零)。如果该字段不是有效金额,则我不需要评估不能为零,而是需要再次检查所有有效金额检查,而不是通过所有有效金额检查control.$validator.amountFormat.
有没有办法保证我构建的格式验证器将在大于零的验证器之前发生。除此之外,我还有许多其他场景。
这是我有:
ctrl.$validators.amountFormat = (modelValue: string, viewValue: string) => {
if (ctrl.$isEmpty(viewValue)) {
return true;
}
return isAmount(viewValue);
}
ctrl.$validators.amountGreaterThanZero = (modelValue: string, viewValue: string) => {
if (!isAmount(viewValue)) { //isAmount() is the function used to determine format
return true;
}
return parseFloat(viewValue) > 0;
}
这是想什么,我有:
ctrl.$validators.amountGreaterThanZero = (modelValue: string, viewValue: string) => {
if (ctrl.$error.amountFormat) {
return true;
}
return parseFloat(viewValue) > 0;
}