Model driven forms is a new concept in angular 2. In angular 1, all we had was template driven forms which by the way, you can still use in Angular 2.

What is a model driven form?

Before we look at why you would want to use model driven forms, what do we mean by model driven forms?

Ng2ModelDrivenForms

Architecturally, a form has 4 parts:

  • DOM. This is where the form is rendered to!
  • Template. This defines how the fields are laid out in the DOM
  • Form Model. This defines the fields on the form and some of the associated UI logic such as what the client side validation rules are and what the default values are
  • Domain Model. This contains the fields and their values

In angular 1, the form model was hidden from us - angular creates this for us from the template. In angular 2 we can create the form model using FormBuilder. Using FormBuilder in Angular 2 is taking the model driven approach.

#angular #typescript

Angular Model Driven Forms
1.65 GEEK