我想通过Angular2中的Validators将一些 validation 添加到表单的字段中:
- 我将 ngForm 绑定到这样的形式:
#form="ngForm"
- 对于我绑定的字段 ngModel :
#field="ngModel", [(ngModel)]="model.field" type="text" name="field" placeholder="field"
new form api建议使用ngForm和ngModel,但angular.io docs中没有如何使用Validators的文档 .
在api reference to NgModel中有 validator : ValidatorFn
和 asyncValidator : AsyncValidatorFn
等属性
但我不知道 how to reference the fields from the component's class to add the validators .