We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FormControl
FormGroup
Validator
control.setErrors()
示例代码:
export const domainValidator = (group: FormGroup) => { const prefixCtrl = group.get('prefix') const prefix: string = prefixCtrl.value const suffix: string = group.get('suffix').value const isPrefixValid = prefix.length + (suffix.length - +suffix.startsWith('*')) <= 20 prefixCtrl.setErrors(isPrefixValid ? null : { maxlength: true }) } export class TestComponent { form = this.fb.group( { prefix: '', suffix: '' }, { validators: domainValidator }, ) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
FormControl
如果需要与其他FormControl
联动检查时,应该在向上一级的FormGroup
中设置相关Validator
并在其中调用control.setErrors()
来设置校验结果,这样可以保证多个FormControl
变动时只需要进行一次校验。示例代码:
The text was updated successfully, but these errors were encountered: