====== Template Driven Form ====== In order to use ngForm, we need to import the Form module ni app.module.ts and your component. ===== component.html ===== When the submit button is clicked, we have the form to call function ''logForm(form.value)''.


==== component.ts ==== import { Component, OnInit } from '@angular/core'; import {Form} from "@angular/forms"; @Component({ selector: 'app-my-form', templateUrl: './my-form.component.html', styleUrls: ['./my-form.component.css'] }) export class MyFormComponent implements OnInit { constructor() { } ngOnInit() { } logForm(value: Form) { console.log(value); } } ==== Output ==== The following output will print in the console. Object { firstName: "first name", lastName: "last name" } ==== Additional Info ==== Item can be grouped by ngModelGroup, such as:



The result would look like the following on click. firstName: "first " ​lastName: "last" ​personalInfo: {…} ​​ address: "my addess, HK" ​​phone: "123456789"