我正在使用响应式表单。我想像这样在 View 中获取 FormControl 的验证器:
<span *ngIf="productForm.controls.ProductName.validator?.required" class="required-field">*</span>
我的组件代码是这样的:
this.productForm = new FormGroup({
'ProductName': new FormControl('', [Validators.required])
})
是否有任何方法可以知道 ProductName 有一个验证器并且这是必需的
最佳答案
可以使用
检查*ngIf = "productForm.controls.Productname.errors.required"
检查输入是否有必需的验证器。
关于angular2-forms - 如何在 HTML View 中获取 FormControl Validator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40969990/