Form Template Example
<form #contactFormTemplate = "ngForm" (ngSubmit)="submitContactForm()">
<input type="text" class="form-control" name="name" [(ngModel)]="formData.name">
<!-- {{name!.value}} -->
<button class="btn btn-primary mr-2" type="submit"
[disabled]="this.contactFormTemplate.status != 'VALID'">Submit</button>
<a class="btn btn-secondary" (click)="clearForm()">Clear All</a>
</form>
Form Component Class
export class FormComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
formData: any = {
name: "",
};
submitContactForm() {
console.log(this.formData); //form values
}
clearForm() {
this.formData.reset(); // not working as intended
}
}