I want to build angular form, I want to know why do we import 'ReactiveFormsModule' in app.module. And then to use different classes like formComtrol, formGroup why do we need to again import them explicitly in template class?
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveComponent } from './reactive/reactive.component'; <-- component class
import { ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent,
ReactiveComponent
],
imports: [
ReactiveFormsModule,
.....
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Reactive.Component.ts
import { Component, OnInit } from '@angular/core';
**import { FormControl } from '@angular/forms';** <---why is this needed as we have already imported forms module in app.module.ts
@Component({
selector: 'app-reactive',
templateUrl: './reactive.component.html',
styleUrls: ['./reactive.component.css']
})
export class ReactiveComponent {
name = new FormControl('');
constructor() { }
ngOnInit(): void {
}
}
My question importing formsModule in app.module.ts does what? And importing class by class separately in component class does what?