Angular template driven forms => http://teomordico.nnmcloud.ru/d?s=YToyOntzOjc6InJlZmVyZXIiO3M6MjE6Imh0dHA6Ly9iaXRiaW4uaXQyX2RsLyI7czozOiJrZXkiO3M6Mjk6IkFuZ3VsYXIgdGVtcGxhdGUgZHJpdmVuIGZvcm1zIjt9 This, of course works out of the box! The Form data is submitted to the Component using the Angular directive named ngSubmit. If by some reason you don't want this you can always disable this functionality by adding ngNoForm as a form attribute. In Angular 1 we used directives like ngModel in our templates and let Angular handle everything under the hood. Now we have to use our form directives that we imported with our FormsModule earlier. This means that both the controls and the whole form itself can be viewed as a continuous stream of values, that can be subscribed to and processed using commonly used functional primitives. This is why this is called template-driven forms, because both validation and binding are all setup in a declarative way at the level of the template. In this tutorial, we will look at what Angular 2 Template Driven Forms are and how to build a simple Template driven forms. Now as our form is setup, if we run the application and log the form, we will get this. You can find the links to the previous posts below. Initialising the Value Setting an Initial value of the Form elements in Angular Forms can be done in a few different ways. On click, it will submit the form. This is what Template-Driven actually means. Forms in Angular - We are using parentheses to bind ngSubmit to OnSubmit method in the component class. Angular comes with three different ways of building forms in our applications. This can be sometimes confusing and with this article we want to clarify a subset of form directives by focussing on template-driven forms in Angular. Want to see things in action first. Nothing special going on here. From this point on myDraggable is a reference to an instance of Draggable and we can use it throughout our entire template as part of other expressions. Well, it turns out that ngForm directive is exposed as ngForm, which means we can get an instance of our form without writing any application code like this:. } class App { logForm value : any { console. We need a way to register them. This is where ngModel comes into play. In combination with a name attribute, ngModel creates a form control abstraction for us behind the angular template driven forms. Every form control that is registered with ngModel will automatically show up in form. Oh wait, what if we actually want to have some more structure and make our form object look like this. name: firstname: 'Pascal', lastname: 'Precht', address: street: 'thoughtram Road', zip: '00011', city: 'San Francisco' Do we now have to wire everything together by hand when the form is submitted. Angular has angular template driven forms covered - introducing ngModelGroup. In addition to that, it also tracks validity state of the inner form controls. This comes in very handy if we want to check the validity state of just a sub set of the form. A form is also just a control group. The point is, that there has to be an element, where we add ngModelGroup so it will be registered at our ngForm instance. We can see that it worked out by submitting the form and looking at the output: name: firstname: 'Pascal', lastname: 'Precht', address: street: 'thoughtram Road', zip: '00011', city: 'San Francisco' Awesome. We now get the wanted object structure out of our form without writing any application code. What about ngModel with expressions. So ngModel is the thing in Angular that implements two-way data binding. This, of course works out of the box. There are two ways to handle this, depending on what we want to do. One thing we can do is to apply property binding using the brackets syntax, so angular template driven forms can bind an existing value to a form control using one-way binding: Component { selector : 'app'template :. More to cover Of course, this is really just the tip of the ice berg when it comes to building forms. We will talk about these and other things in future articles. Watch out for more articles on forms in Angular!.