저는 JS/Typescript 및 Angular 2로 시작 했으므로 다음과 같이 고민하고 있습니다.각도 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;
};
}
이는 발리 공장의 아주 기본적인 예이다.
모든 예제 난 그냥 (I 템플릿 양식을 사용하고 있습니다)
는 검증 자체를 사용 매개 변수에 검증 메시지 "를 묶어"수 있나요 템플릿에서 직접 확인 메시지/오류를 썼다 발견 그것?
좋아 :
'Min width has to be 100. you supplied ' + actualWidth
이
는 검증 자체에서 반환됩니다.또는 다른 방법이 있습니까 (변수를 어딘가에 저장하는 것과 별도)?