I want to add some validation to the fields of a form through Validators in Angular2:
- I'm binding ngForm to a form like this:
#form="ngForm"
- For the fields i'm binding ngModel:
#field="ngModel", [(ngModel)]="model.field" type="text" name="field" placeholder="field"
The new form api suggests to use ngForm and ngModel, but there is no documentation in angular.io docs how to use Validators.
In the api reference to NgModel there are properties like
validator : ValidatorFn
and asyncValidator : AsyncValidatorFn
But i don't know how to reference the fields from the component's class to add the validators.