How to initialize template driven form?

Anil Kumar
Jun 28, 2023

--

Photo by Shubham Dhage on Unsplash
  1. Import Form module
  2. In Component create the variables in ts /class file
  3. set input with ngModel

import { Component } from '@angular/core';

@Component({
selector: 'app-my-component',
styleUrls: ['./my-component.component.css'],
template: `
Name: <input type="text" [(ngModel)]="myData.name">
Age: <input type="number" [(ngModel)]="myData.age">
`
})
export class MyComponent {
myData = { name: '', age: ''}

}

--

--