我刚刚开始使用JS/Typescript和Angular 2,并且我正在努力处理以下内容。Angular 2,带参数的自定义验证消息
export function MinImageDimensionsValidator(minWidth: number, minHeight: number): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } => {
// it's an image control where a user uploads an image.
// the whole image related code has been removed for better readability.
//Just assume that 'actualWidth' holds the actual width of the image
if(actualWidth < minWidth) {
return { valid: false };
}
return null;
};
}
这仅仅是一个验证器工厂的一个非常基本的例子。
所有的例子,我发现只是写在模板中的验证消息/直接错误(我使用模板的形式)
是否可以“配合”的验证消息的验证器本身和使用参数与它?
喜欢:
'Min width has to be 100. you supplied ' + actualWidth
这会从验证自身返回。
还是有另一种方式(除了将变量存储在某处)?