ngControl registers an HTML form control with Angular’s validation system. Place the control inside a form and give it a name; Angular then tracks its validation state and updates the control and form classes automatically. section 13.4.2
Use ngControl with:
- A containing form, because Angular validation reports an error when the directive is used outside one. section 13.4.2
Validated product name
<form (ngSubmit)="addProduct(newProduct)"><input name="name" [(ngModel)]="newProduct.name" #name="ngModel" required minlength="5" pattern="^[A-Za-z ]+$"></form>. Display messages when name.dirty && name.invalid, checking name.errors for required, pattern, or minlength.
