0

I am trying to Create one ReactiveFormModule in Angular 9. I have included ReactiveFormModule and FormsModule in app.component.ts. But still While executing the application getting error. Below are the code,

**Angular 9.1
Nodejs 12.16**

**app.module.ts**
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
  ....
    FormsModule,
    ReactiveFormsModule
  ],
  exports: [ReactiveFormsModule,FormsModule],
  ....
})
export class AppModule { }

**in Home component.html file**
<form [formGroup] = "myForm">
                <input type="text" formControlName = "inputValue" class="form-control" (keyup) = "fnChnageText(myForm.value)" >
            </form>

**in home.component.ts**
myForm : FormGroup;
  inputValue : string;

  constructor(private fb:FormBuilder) {
     this.myForm = this.fb.group({
      inputValue : ['',Validators.required]
     });
   }

After running the application getting error - can't bind to the formGroup. How to resolve this. Please help me

1 Answer 1

1

You don't need to declare inputValue seperately. The formControlName you have defined will directly watch inside your FormBuilder group and see if it's present. Also you need to import FormBuilder and Validators from @angular/forms

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.