In order to use reactive forms in Angular you need to first import the appropiate module onto your targeted module.ts
file. E.g: app.module.ts
this way:
@NgModule({
declarations: [
AppComponent
.
.],
imports:[
.
.
ReactiveFormsModule],
entryComponents:[..],
providers: []
....
Then your target component some.component.ts
should look something like this:
myForm = this.fb.group({
field1:['',[Validators.required,...]],
field2: ....
)};
constructor(private fb: FormBuilder, ...){}
Then in your html file some.component.html
file you just show your form like this:
<form [formGroup]="myForm" (ngSubmit)="yourSubmitFunction(myForm)">
<div>
<input formControlName="field1" >
</div>
.
.
.
<button type="submit">Submit</button>
</form>
Hope this helps you!.