How to initialize template driven form?
Jun 28, 2023
- Import Form module
- In Component create the variables in ts /class file
- 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: ''}
}