At the time of Reactive Forms Validate, I got this error: No directive found with exportAs 'ngForm'.ngtsc(-998003)
After that, I added to ReactiveFormsModule in the imports[] array to resolve this error.
import { CommonModule } from '@angular/common';
import { NgForm,FormsModule, ReactiveFormsModule } from '@angular/forms';
In Component class,
imports: [RouterOutlet, FormsModule, ReactiveFormsModule, CommonModule]
Example,
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { NgForm,FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterOutlet } from '@angular/router';
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet,FormsModule,ReactiveFormsModule,CommonModule],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent {
title = 'Form Validation';
form = {
fullname: '',
username: '',
email: '',
password: '',
confirmPassword: '',
acceptTerms: false,
};
onSubmit(): void {
console.log(JSON.stringify(this.form, null, 2));
}
onReset(form: NgForm): void {
form.reset();
}
}
Reactive forms validation in Angular 17:- https://youtu.be/rAYqQtIPTFE
Download source code from Github:- https://github.com/anilsingh581/Angular-17-reactive-Form-Validation