Can t bind to formGroup since it isn t a known property of form

0 votes
Can you tell me if Can't bind to 'formGroup' since it isn't a known property of 'form'?
Mar 11 in Java-Script by Ashutosh
• 23,230 points
67 views

1 answer to this question.

0 votes

The error Can't bind to 'formGroup' since it isn't a known property of 'form' occurs in Angular when the ReactiveFormsModule is not imported into your module. This module is required to use reactive forms, including the formGroup directive.

Solution: Import ReactiveFormsModule

Open the Module File:

Locate the module file where your component is declared (e.g., app.module.ts).

Import ReactiveFormsModule:

Example:

import { NgModule } from '@angular/core';

import { BrowserModule } from '@angular/platform-browser';

import { ReactiveFormsModule } from '@angular/forms'; // Import ReactiveFormsModule

import { AppComponent } from './app.component';

@NgModule({

  declarations: [

    AppComponent

  ],

  imports: [

    BrowserModule,

    ReactiveFormsModule // Add ReactiveFormsModule here

  ],

  providers: [],

  bootstrap: [AppComponent]

})

export class AppModule { }

Verify the Component Code

Ensure your component is correctly using the formGroup directive.

Example Component:

import { Component } from '@angular/core';

import { FormBuilder, FormGroup } from '@angular/forms';

@Component({

  selector: 'app-root',

  template: `

    <form [formGroup]="myForm" (ngSubmit)="onSubmit()">

      <input formControlName="name" placeholder="Name">

      <button type="submit">Submit</button>

    </form>

  `

})

export class AppComponent {

  myForm: FormGroup;

  constructor(private fb: FormBuilder) {

    this.myForm = this.fb.group({

      name: ['']

    });

  }

  onSubmit() {

    console.log(this.myForm.value);

  }

}

answered Mar 11 by Tanvi

Related Questions In Java-Script

+1 vote
1 answer

How to implement up and down voting of a particular thread?

Hello @kartik, Yes, JavaScript is involved. There are ...READ MORE

answered Jun 3, 2020 in Java-Script by Niroj
• 82,840 points
1,565 views
0 votes
1 answer

How to list the properties of a JavaScript object?

Hii @kartik, Use Reflect.ownKeys(): var obj = {a: 1, b: ...READ MORE

answered Jun 8, 2020 in Java-Script by Niroj
• 82,840 points
1,145 views
0 votes
1 answer

How do I add arbitrary html attributes to input fields on a form?

Hello @kartik, If you are using ModelForm, apart from ...READ MORE

answered Jul 27, 2020 in Java-Script by Niroj
• 82,840 points
1,147 views
0 votes
1 answer

How to replace all occurrences of a string?

Hello @kartik, As an alternative to regular expressions ...READ MORE

answered Aug 28, 2020 in Java-Script by Niroj
• 82,840 points
967 views
0 votes
1 answer

How to Center a Single-Column Div Within a 12-Column Container in Bootstrap 3?

Using Bootstrap's Offset Classes Bootstrap 3 provides offset ...READ MORE

answered Mar 11 in Node-js by Tanvi
67 views
0 votes
1 answer

How to get current financial year in PHP?

You can get the current financial year ...READ MORE

answered Mar 11 in Laravel by Sanvi
102 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP