【发布时间】:2021-02-20 13:29:14
【问题描述】:
在我看来,Dynamically generating validation attribute on input using interpolation 中提出的问题完全相同,但我正在寻找Angular 中的解决方案,而不是AngularJS。
在我的响应式表单中,我使用了这样的验证器:
public contactForm: FormGroup = this.formBuilder.group({
...
formControlDescription: [
'',
Validators.compose([
Validators.maxLength(5000),
Validators.minLength(30),
Validators.required,
]),
],
...
});
在html 上,我正在以这种方式对号码5000 进行硬编码:
<mat-hint align="end">{{ contactForm.get('formControlDescription')!.value.length }} / 5000</mat-hint>
问题:有没有办法动态访问html中的contactForm的formControlDescription的Validators.maxLength(5000)?
【问题讨论】:
-
您首先从哪里获得 5000 值?
-
在
html?它是硬编码的。
标签: angular typescript angular-reactive-forms reactive-forms angular-validation