Solved – can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’

In this article, you will learn how to solve can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’ error in Angular. Let’s look…

The post Solved – can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’ appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven

In this article, you will learn how to solve can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’ error in Angular.

Let’s look at a code example that produces the same error.

app.component.html

<form [formGroup]="myForm">
  Naam: <input type="text" formControlName="name"><br>
  Age: <input type="number" formControlName="age">

  <button>Save</button>
</form>

app.component.ts

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
	selector: 'app-root',
	templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
	myForm: FormGroup;

	constructor(private fb: FormBuilder) { }

	ngOnInit() {
		this.myForm = this.fb.group({
			name: ['', Validators.required],
			age: ['', Validators.required]
		});
	}
}

Output on when running the application

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

In order to solve can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’ error you need to import ReactiveFormsModule in each submodule file.

app.module.ts

 import { FormsModule, ReactiveFormsModule } from '@angular/forms';`

@NgModule({
  declarations: [
    AppComponent,
  ]
  imports: [
    FormsModule,
    ReactiveFormsModule,
    yourSubModule,
],
...

You need to import ReactiveFormsModule in your yourSubModule like below:

...
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

...

@NgModule({
  imports: [
    ...,
    FormsModule,    //import here
    ReactiveFormsModule //import here
  ],
  declarations: [...],
  providers: [...]
})

export class yourSubModule {}

The post Solved – can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’ appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven


Print Share Comment Cite Upload Translate Updates
APA

Deven | Sciencx (2021-03-12T12:09:42+00:00) Solved – can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’. Retrieved from https://www.scien.cx/2021/03/12/solved-cant-bind-to-formgroup-since-it-isnt-a-known-property-of-form/

MLA
" » Solved – can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’." Deven | Sciencx - Friday March 12, 2021, https://www.scien.cx/2021/03/12/solved-cant-bind-to-formgroup-since-it-isnt-a-known-property-of-form/
HARVARD
Deven | Sciencx Friday March 12, 2021 » Solved – can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’., viewed ,<https://www.scien.cx/2021/03/12/solved-cant-bind-to-formgroup-since-it-isnt-a-known-property-of-form/>
VANCOUVER
Deven | Sciencx - » Solved – can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/12/solved-cant-bind-to-formgroup-since-it-isnt-a-known-property-of-form/
CHICAGO
" » Solved – can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’." Deven | Sciencx - Accessed . https://www.scien.cx/2021/03/12/solved-cant-bind-to-formgroup-since-it-isnt-a-known-property-of-form/
IEEE
" » Solved – can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’." Deven | Sciencx [Online]. Available: https://www.scien.cx/2021/03/12/solved-cant-bind-to-formgroup-since-it-isnt-a-known-property-of-form/. [Accessed: ]
rf:citation
» Solved – can’t bind to ‘formgroup’ since it isn’t a known property of ‘form’ | Deven | Sciencx | https://www.scien.cx/2021/03/12/solved-cant-bind-to-formgroup-since-it-isnt-a-known-property-of-form/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.