What I found really confusing in angular2 forms is that there are two completely different ways to create them, and the two methods do not mix well. You have a “managed template” where the form is built and processed as much as possible in html, and then you have a “managed model” where the form is processed from the component side.
The best description of the various types that I have found is a video where Kara Erickson demonstrates both. She very well explains the differences between the marks of 10-11 minutes:
https://www.youtube.com/watch?v=E92KS_YCSf8
In short:
Template Driven Forms
If you want to perform all form processing (binding, validation, etc.) in an html template, use the following directives:
- ngModel
- ngModelGroup
- ngForm
Molded Models (also known as Reactive Forms )
If you want to have finer controls, better testability, custom validators, etc., generate the form manually in the component using these controls:
- Formgroup
- Formcontrol
- FormArray
- optionally use
FormBuilder to reduce some templates
Then bind the html form and input elements to these controls using the following directives:
- formControlName
- formGroupName
Edit 2016-09-02: There is a good cookbook in the white papers with good coverage of the differences between the templates / reactive forms: https://angular.io/docs/ts/latest/cookbook/form-validation.html
source share