Can't bind to 'formGroup' since it isn't a known property of 'form'
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
THE SITUATION:
Please help! I am trying to make what should be a very simple form in my Angular2 app but no matter what it never works.
ANGULAR VERSION:
Angular 2.0.0 Rc5
THE ERROR:
Can't bind to 'formGroup' since it isn't a known property of 'form'
THE CODE:
The view:
<form [formGroup]="newTaskForm" (submit)="createNewTask()">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" required>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
The controller:
import { Component } from '@angular/core';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import {FormsModule,ReactiveFormsModule} from '@angular/forms';
import { Task } from './task';
@Component({
selector: 'task-add',
templateUrl: 'app/task-add.component.html'
})
export class TaskAddComponent {
newTaskForm: FormGroup;
constructor(fb: FormBuilder)
{
this.newTaskForm = fb.group({
name: ["", Validators.required]
});
}
createNewTask()
{
console.log(this.newTaskForm.value)
}
}
The ngModule:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { routing } from './app.routing';
import { AppComponent } from './app.component';
import { TaskService } from './task.service'
@NgModule({
imports: [
BrowserModule,
routing,
FormsModule
],
declarations: [ AppComponent ],
providers: [
TaskService
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
THE QUESTION:
Why am I getting that error?
Am I missing something?
angular typescript angular2-forms
add a comment |
THE SITUATION:
Please help! I am trying to make what should be a very simple form in my Angular2 app but no matter what it never works.
ANGULAR VERSION:
Angular 2.0.0 Rc5
THE ERROR:
Can't bind to 'formGroup' since it isn't a known property of 'form'
THE CODE:
The view:
<form [formGroup]="newTaskForm" (submit)="createNewTask()">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" required>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
The controller:
import { Component } from '@angular/core';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import {FormsModule,ReactiveFormsModule} from '@angular/forms';
import { Task } from './task';
@Component({
selector: 'task-add',
templateUrl: 'app/task-add.component.html'
})
export class TaskAddComponent {
newTaskForm: FormGroup;
constructor(fb: FormBuilder)
{
this.newTaskForm = fb.group({
name: ["", Validators.required]
});
}
createNewTask()
{
console.log(this.newTaskForm.value)
}
}
The ngModule:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { routing } from './app.routing';
import { AppComponent } from './app.component';
import { TaskService } from './task.service'
@NgModule({
imports: [
BrowserModule,
routing,
FormsModule
],
declarations: [ AppComponent ],
providers: [
TaskService
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
THE QUESTION:
Why am I getting that error?
Am I missing something?
angular typescript angular2-forms
add a comment |
THE SITUATION:
Please help! I am trying to make what should be a very simple form in my Angular2 app but no matter what it never works.
ANGULAR VERSION:
Angular 2.0.0 Rc5
THE ERROR:
Can't bind to 'formGroup' since it isn't a known property of 'form'
THE CODE:
The view:
<form [formGroup]="newTaskForm" (submit)="createNewTask()">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" required>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
The controller:
import { Component } from '@angular/core';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import {FormsModule,ReactiveFormsModule} from '@angular/forms';
import { Task } from './task';
@Component({
selector: 'task-add',
templateUrl: 'app/task-add.component.html'
})
export class TaskAddComponent {
newTaskForm: FormGroup;
constructor(fb: FormBuilder)
{
this.newTaskForm = fb.group({
name: ["", Validators.required]
});
}
createNewTask()
{
console.log(this.newTaskForm.value)
}
}
The ngModule:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { routing } from './app.routing';
import { AppComponent } from './app.component';
import { TaskService } from './task.service'
@NgModule({
imports: [
BrowserModule,
routing,
FormsModule
],
declarations: [ AppComponent ],
providers: [
TaskService
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
THE QUESTION:
Why am I getting that error?
Am I missing something?
angular typescript angular2-forms
THE SITUATION:
Please help! I am trying to make what should be a very simple form in my Angular2 app but no matter what it never works.
ANGULAR VERSION:
Angular 2.0.0 Rc5
THE ERROR:
Can't bind to 'formGroup' since it isn't a known property of 'form'
THE CODE:
The view:
<form [formGroup]="newTaskForm" (submit)="createNewTask()">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" required>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
The controller:
import { Component } from '@angular/core';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import {FormsModule,ReactiveFormsModule} from '@angular/forms';
import { Task } from './task';
@Component({
selector: 'task-add',
templateUrl: 'app/task-add.component.html'
})
export class TaskAddComponent {
newTaskForm: FormGroup;
constructor(fb: FormBuilder)
{
this.newTaskForm = fb.group({
name: ["", Validators.required]
});
}
createNewTask()
{
console.log(this.newTaskForm.value)
}
}
The ngModule:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { routing } from './app.routing';
import { AppComponent } from './app.component';
import { TaskService } from './task.service'
@NgModule({
imports: [
BrowserModule,
routing,
FormsModule
],
declarations: [ AppComponent ],
providers: [
TaskService
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
THE QUESTION:
Why am I getting that error?
Am I missing something?
angular typescript angular2-forms
angular typescript angular2-forms
edited Feb 7 '17 at 8:38
FrancescoMussi
asked Aug 25 '16 at 18:09
FrancescoMussiFrancescoMussi
5,4282696148
5,4282696148
add a comment |
add a comment |
13 Answers
13
active
oldest
votes
RC5 FIX
You need to import { REACTIVE_FORM_DIRECTIVES } from '@angular/forms'
in your controller and add it to directives
in @Component
. That will fix the problem.
After you fix that, you will probably get another error because you didn't add formControlName="name"
to your input in form.
RC6/RC7/Final release FIX
To fix this error, you just need to import ReactiveFormsModule
from @angular/forms
in your module. Here's the example of a basic module with ReactiveFormsModule
import:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
AppComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }
To explain further, formGroup
is a selector for directive named FormGroupDirective
that is a part of ReactiveFormsModule
, hence the need to import it. It is used to bind an existing FormGroup
to a DOM element. You can read more about it on Angular's official docs page.
9
What I don't get is why one needs to add REACTIVE_FORM_DIRECTIVES if FormsModule is being imported inside app.module. The whole point of modules is to avoid having to declare directives inside components.
– Daniel Pliscki
Sep 1 '16 at 14:21
13
@DanielPliscki You are completely right, I just found out they fixed this problem in RC6 version that was released today. Now you don't need to do this, you only need to importFormsModule
andReactiveFormsModule
. I will edit my answer.
– Stefan Svrkota
Sep 1 '16 at 14:24
10
I LOST AN HOUR completing forgetting that I created a separate module for my login form in order to lazy load with modules between states. (I am new to A2, still prefer A1) Please make sure you use the right module! Don't be a schmuck like me. You also no longer need to add to the component. The imports in your module suffice. Thanks
– user1889992
Mar 18 '17 at 23:55
4
Thanks, worked for me. I am confused why this is not mentioned in the guides for FormControls in Angular 2 that I have stumbled upon..
– cjohansson
Apr 19 '17 at 8:14
2
it is not working for me... now, what I will do..??
– Deepak Chawla
Jul 15 '17 at 5:51
|
show 7 more comments
Angular 4 in combination with feature modules (if you are for instance using a shared-module) requires you to also export the ReactiveFormsModule
to work.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
CommonModule,
ReactiveFormsModule
],
declarations: ,
exports: [
CommonModule,
FormsModule,
ReactiveFormsModule
]
})
export class SharedModule { }
add a comment |
Ok after some digging I found a solution for "Can't bind to 'formGroup' since it isn't a known property of 'form'."
For my case, I've been using multiple modules files, i added ReactiveFormsModule in app.module.ts
import { FormsModule, ReactiveFormsModule } from '@angular/forms';`
@NgModule({
declarations: [
AppComponent,
]
imports: [
FormsModule,
ReactiveFormsModule,
AuthorModule,
],
...
But this wasn't working when I use a [formGroup] directive from a component added in another module, e.g. using [formGroup] in author.component.ts which is subscribed in author.module.ts file:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AuthorComponent } from './author.component';
@NgModule({
imports: [
CommonModule,
],
declarations: [
AuthorComponent,
],
providers: [...]
})
export class AuthorModule {}
I thought if i added ReactiveFormsModule in app.module.ts, by default ReactiveFormsModule would be inherited by all its children modules like author.module in this case... (wrong!).
I needed to import ReactiveFormsModule in author.module.ts in order to make all directives to work:
...
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
...
@NgModule({
imports: [
...,
FormsModule, //added here too
ReactiveFormsModule //added here too
],
declarations: [...],
providers: [...]
})
export class AuthorModule {}
So, if you are using submodules, make sure to import ReactiveFormsModule in each submodule file.
Hope this helps anyone.
2
Thank you for providing the story as well. This is exactly what I've wasted my time on for 2 days now...
– ntgCleaner
Aug 12 '18 at 18:33
1
Works for me, exactly the same problem, I really thought modules in exports array will be inherited by children modules... Don't know why exactly ! EDIT : documentation says exports is to make components, pipes, directives available in the TEMPLATE of any COMPONENT ()
– guy777
Nov 22 '18 at 21:24
1
Thank you! Thank you! Thank you! Thank you for the good explanation and the code. It finally works
– Kenji Elzerman
Jan 18 at 8:45
add a comment |
I have encountered this error during unit testing of a component (only during testing, within application it worked normally). The solution is to import ReactiveFormsModule
in .spec.ts
file:
// Import module
import { ReactiveFormsModule } from '@angular/forms';
describe('MyComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [MyComponent],
imports: [ReactiveFormsModule], // Also add it to 'imports' array
})
.compileComponents();
}));
});
Precisely the problem I was encountering. This solution worked perfectly!
– Bill Dagg
Feb 1 at 17:35
add a comment |
The suggested answer did not work for me with Angular 4. Instead I had to use another way of attribute binding with the attr
prefix:
<element [attr.attribute-to-bind]="someValue">
2
Hey man! Are you sure your answer is related to the question? :) The question was about an issue setting up a form - cause by not properly setting up the ngModule
– FrancescoMussi
Apr 26 '17 at 14:24
@johnnyfittizio Pretty sure. Same scenario, same error message.
– str
Apr 26 '17 at 14:47
1
This worked for me, but is strange - why do I need theattr.
?
– CodyBugstein
Oct 26 '17 at 21:17
@CodyBugstein See angular.io/guide/template-syntax#attribute-binding
– str
Oct 27 '17 at 10:04
Thanks a ton. This worked for me also, but I would think there must be something else triggering the problem, like library versioning, or <form> tag positioning? Strange.
– Memetican
Mar 14 at 23:33
|
show 1 more comment
If you have to import two modules then add like this below
import {ReactiveFormsModule,FormsModule} from '@angular/forms';
@NgModule({
declarations: [
AppComponent,
HomeComponentComponent,
BlogComponentComponent,
ContactComponentComponent,
HeaderComponentComponent,
FooterComponentComponent,
RegisterComponent,
LoginComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
routes,
ReactiveFormsModule
],
providers: ,
bootstrap: [AppComponent]
})
add a comment |
Keep in mind that if you have defined "Feature Modules", you'll need to import in the Feature Module, even if you already imported to the AppModule
. From the Angular documentation:
Modules don't inherit access to the components, directives, or pipes that are declared in other modules. What AppModule imports is irrelevant to ContactModule and vice versa. Before ContactComponent can bind with [(ngModel)], its ContactModule must import FormsModule.
https://angular.io/docs/ts/latest/guide/ngmodule.html
add a comment |
I had the same issue with Angular 7. Just import following in your app.module.ts file.
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Then add FormsModule and ReactiveFormsModule in to your imports array.
imports: [
FormsModule,
ReactiveFormsModule
],
add a comment |
This problem occurs due to missing import of FormsModule,ReactiveFormsModule .I also came with same problem.
My case was diff. as i was working with modules.So i missed above imports in my parent modules though i had imported it into child modules,it wasn't working.
Then i imported it into my parent modules as below, and it worked!
import { ReactiveFormsModule,FormsModule } from '@angular/forms';
import { AlertModule } from 'ngx-bootstrap';
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
],
declarations: [MyComponent]
})
add a comment |
For people strolling these threads about this error. In my case I had a shared module where I only exported the FormsModule and ReactiveFormsModule and forgot to import it. This caused a strange error that formgroups were not working in sub components. Hope this helps people scratching their heads.
add a comment |
I was coming across this error when trying to do e2e testing and it was driving me crazy that there were no answers to this.
IF YOU ARE DOING TESTING, find your *.specs.ts file and add :
import {ReactiveFormsModule, FormsModule} from '@angular/forms';
add a comment |
A LITTLE NOTE: Be careful about loaders and minimize (Rails env.):
After seeing this error and trying every solution out there, i realised there was something wrong with my html loader.
I've set my Rails environment up to import HTML paths for my components successfully with this loader (config/loaders/html.js.
):
module.exports = {
test: /.html$/,
use: [ {
loader: 'html-loader?exportAsEs6Default',
options: {
minimize: true
}
}]
}
After some hours efforts and countless of ReactiveFormsModule imports i saw that my formGroup
was small letters: formgroup
.
This led me to the loader and the fact that it downcased my HTML on minimize.
After changing the options, everything worked as it should, and i could go back to crying again.
I know that this is not an answer to the question, but for future Rails visitors (and other with custom loaders) i think this could be helpfull.
add a comment |
Can't bind to 'formGroup' since it isn't a known property of 'form'
means that you try to bind a property using angular ([prop]
) but angular cant find anything he knows for that element (in this case form
).
this can happen by not using the right module (missing an import somewhere in the way) and sometimes just cause a typo like:
[formsGroup]
, with s
after form
add a comment |
protected by Günter Zöchbauer Oct 18 '17 at 8:21
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
13 Answers
13
active
oldest
votes
13 Answers
13
active
oldest
votes
active
oldest
votes
active
oldest
votes
RC5 FIX
You need to import { REACTIVE_FORM_DIRECTIVES } from '@angular/forms'
in your controller and add it to directives
in @Component
. That will fix the problem.
After you fix that, you will probably get another error because you didn't add formControlName="name"
to your input in form.
RC6/RC7/Final release FIX
To fix this error, you just need to import ReactiveFormsModule
from @angular/forms
in your module. Here's the example of a basic module with ReactiveFormsModule
import:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
AppComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }
To explain further, formGroup
is a selector for directive named FormGroupDirective
that is a part of ReactiveFormsModule
, hence the need to import it. It is used to bind an existing FormGroup
to a DOM element. You can read more about it on Angular's official docs page.
9
What I don't get is why one needs to add REACTIVE_FORM_DIRECTIVES if FormsModule is being imported inside app.module. The whole point of modules is to avoid having to declare directives inside components.
– Daniel Pliscki
Sep 1 '16 at 14:21
13
@DanielPliscki You are completely right, I just found out they fixed this problem in RC6 version that was released today. Now you don't need to do this, you only need to importFormsModule
andReactiveFormsModule
. I will edit my answer.
– Stefan Svrkota
Sep 1 '16 at 14:24
10
I LOST AN HOUR completing forgetting that I created a separate module for my login form in order to lazy load with modules between states. (I am new to A2, still prefer A1) Please make sure you use the right module! Don't be a schmuck like me. You also no longer need to add to the component. The imports in your module suffice. Thanks
– user1889992
Mar 18 '17 at 23:55
4
Thanks, worked for me. I am confused why this is not mentioned in the guides for FormControls in Angular 2 that I have stumbled upon..
– cjohansson
Apr 19 '17 at 8:14
2
it is not working for me... now, what I will do..??
– Deepak Chawla
Jul 15 '17 at 5:51
|
show 7 more comments
RC5 FIX
You need to import { REACTIVE_FORM_DIRECTIVES } from '@angular/forms'
in your controller and add it to directives
in @Component
. That will fix the problem.
After you fix that, you will probably get another error because you didn't add formControlName="name"
to your input in form.
RC6/RC7/Final release FIX
To fix this error, you just need to import ReactiveFormsModule
from @angular/forms
in your module. Here's the example of a basic module with ReactiveFormsModule
import:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
AppComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }
To explain further, formGroup
is a selector for directive named FormGroupDirective
that is a part of ReactiveFormsModule
, hence the need to import it. It is used to bind an existing FormGroup
to a DOM element. You can read more about it on Angular's official docs page.
9
What I don't get is why one needs to add REACTIVE_FORM_DIRECTIVES if FormsModule is being imported inside app.module. The whole point of modules is to avoid having to declare directives inside components.
– Daniel Pliscki
Sep 1 '16 at 14:21
13
@DanielPliscki You are completely right, I just found out they fixed this problem in RC6 version that was released today. Now you don't need to do this, you only need to importFormsModule
andReactiveFormsModule
. I will edit my answer.
– Stefan Svrkota
Sep 1 '16 at 14:24
10
I LOST AN HOUR completing forgetting that I created a separate module for my login form in order to lazy load with modules between states. (I am new to A2, still prefer A1) Please make sure you use the right module! Don't be a schmuck like me. You also no longer need to add to the component. The imports in your module suffice. Thanks
– user1889992
Mar 18 '17 at 23:55
4
Thanks, worked for me. I am confused why this is not mentioned in the guides for FormControls in Angular 2 that I have stumbled upon..
– cjohansson
Apr 19 '17 at 8:14
2
it is not working for me... now, what I will do..??
– Deepak Chawla
Jul 15 '17 at 5:51
|
show 7 more comments
RC5 FIX
You need to import { REACTIVE_FORM_DIRECTIVES } from '@angular/forms'
in your controller and add it to directives
in @Component
. That will fix the problem.
After you fix that, you will probably get another error because you didn't add formControlName="name"
to your input in form.
RC6/RC7/Final release FIX
To fix this error, you just need to import ReactiveFormsModule
from @angular/forms
in your module. Here's the example of a basic module with ReactiveFormsModule
import:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
AppComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }
To explain further, formGroup
is a selector for directive named FormGroupDirective
that is a part of ReactiveFormsModule
, hence the need to import it. It is used to bind an existing FormGroup
to a DOM element. You can read more about it on Angular's official docs page.
RC5 FIX
You need to import { REACTIVE_FORM_DIRECTIVES } from '@angular/forms'
in your controller and add it to directives
in @Component
. That will fix the problem.
After you fix that, you will probably get another error because you didn't add formControlName="name"
to your input in form.
RC6/RC7/Final release FIX
To fix this error, you just need to import ReactiveFormsModule
from @angular/forms
in your module. Here's the example of a basic module with ReactiveFormsModule
import:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
AppComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }
To explain further, formGroup
is a selector for directive named FormGroupDirective
that is a part of ReactiveFormsModule
, hence the need to import it. It is used to bind an existing FormGroup
to a DOM element. You can read more about it on Angular's official docs page.
edited Sep 28 '16 at 0:13
answered Aug 25 '16 at 18:11
Stefan SvrkotaStefan Svrkota
26.6k56775
26.6k56775
9
What I don't get is why one needs to add REACTIVE_FORM_DIRECTIVES if FormsModule is being imported inside app.module. The whole point of modules is to avoid having to declare directives inside components.
– Daniel Pliscki
Sep 1 '16 at 14:21
13
@DanielPliscki You are completely right, I just found out they fixed this problem in RC6 version that was released today. Now you don't need to do this, you only need to importFormsModule
andReactiveFormsModule
. I will edit my answer.
– Stefan Svrkota
Sep 1 '16 at 14:24
10
I LOST AN HOUR completing forgetting that I created a separate module for my login form in order to lazy load with modules between states. (I am new to A2, still prefer A1) Please make sure you use the right module! Don't be a schmuck like me. You also no longer need to add to the component. The imports in your module suffice. Thanks
– user1889992
Mar 18 '17 at 23:55
4
Thanks, worked for me. I am confused why this is not mentioned in the guides for FormControls in Angular 2 that I have stumbled upon..
– cjohansson
Apr 19 '17 at 8:14
2
it is not working for me... now, what I will do..??
– Deepak Chawla
Jul 15 '17 at 5:51
|
show 7 more comments
9
What I don't get is why one needs to add REACTIVE_FORM_DIRECTIVES if FormsModule is being imported inside app.module. The whole point of modules is to avoid having to declare directives inside components.
– Daniel Pliscki
Sep 1 '16 at 14:21
13
@DanielPliscki You are completely right, I just found out they fixed this problem in RC6 version that was released today. Now you don't need to do this, you only need to importFormsModule
andReactiveFormsModule
. I will edit my answer.
– Stefan Svrkota
Sep 1 '16 at 14:24
10
I LOST AN HOUR completing forgetting that I created a separate module for my login form in order to lazy load with modules between states. (I am new to A2, still prefer A1) Please make sure you use the right module! Don't be a schmuck like me. You also no longer need to add to the component. The imports in your module suffice. Thanks
– user1889992
Mar 18 '17 at 23:55
4
Thanks, worked for me. I am confused why this is not mentioned in the guides for FormControls in Angular 2 that I have stumbled upon..
– cjohansson
Apr 19 '17 at 8:14
2
it is not working for me... now, what I will do..??
– Deepak Chawla
Jul 15 '17 at 5:51
9
9
What I don't get is why one needs to add REACTIVE_FORM_DIRECTIVES if FormsModule is being imported inside app.module. The whole point of modules is to avoid having to declare directives inside components.
– Daniel Pliscki
Sep 1 '16 at 14:21
What I don't get is why one needs to add REACTIVE_FORM_DIRECTIVES if FormsModule is being imported inside app.module. The whole point of modules is to avoid having to declare directives inside components.
– Daniel Pliscki
Sep 1 '16 at 14:21
13
13
@DanielPliscki You are completely right, I just found out they fixed this problem in RC6 version that was released today. Now you don't need to do this, you only need to import
FormsModule
and ReactiveFormsModule
. I will edit my answer.– Stefan Svrkota
Sep 1 '16 at 14:24
@DanielPliscki You are completely right, I just found out they fixed this problem in RC6 version that was released today. Now you don't need to do this, you only need to import
FormsModule
and ReactiveFormsModule
. I will edit my answer.– Stefan Svrkota
Sep 1 '16 at 14:24
10
10
I LOST AN HOUR completing forgetting that I created a separate module for my login form in order to lazy load with modules between states. (I am new to A2, still prefer A1) Please make sure you use the right module! Don't be a schmuck like me. You also no longer need to add to the component. The imports in your module suffice. Thanks
– user1889992
Mar 18 '17 at 23:55
I LOST AN HOUR completing forgetting that I created a separate module for my login form in order to lazy load with modules between states. (I am new to A2, still prefer A1) Please make sure you use the right module! Don't be a schmuck like me. You also no longer need to add to the component. The imports in your module suffice. Thanks
– user1889992
Mar 18 '17 at 23:55
4
4
Thanks, worked for me. I am confused why this is not mentioned in the guides for FormControls in Angular 2 that I have stumbled upon..
– cjohansson
Apr 19 '17 at 8:14
Thanks, worked for me. I am confused why this is not mentioned in the guides for FormControls in Angular 2 that I have stumbled upon..
– cjohansson
Apr 19 '17 at 8:14
2
2
it is not working for me... now, what I will do..??
– Deepak Chawla
Jul 15 '17 at 5:51
it is not working for me... now, what I will do..??
– Deepak Chawla
Jul 15 '17 at 5:51
|
show 7 more comments
Angular 4 in combination with feature modules (if you are for instance using a shared-module) requires you to also export the ReactiveFormsModule
to work.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
CommonModule,
ReactiveFormsModule
],
declarations: ,
exports: [
CommonModule,
FormsModule,
ReactiveFormsModule
]
})
export class SharedModule { }
add a comment |
Angular 4 in combination with feature modules (if you are for instance using a shared-module) requires you to also export the ReactiveFormsModule
to work.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
CommonModule,
ReactiveFormsModule
],
declarations: ,
exports: [
CommonModule,
FormsModule,
ReactiveFormsModule
]
})
export class SharedModule { }
add a comment |
Angular 4 in combination with feature modules (if you are for instance using a shared-module) requires you to also export the ReactiveFormsModule
to work.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
CommonModule,
ReactiveFormsModule
],
declarations: ,
exports: [
CommonModule,
FormsModule,
ReactiveFormsModule
]
})
export class SharedModule { }
Angular 4 in combination with feature modules (if you are for instance using a shared-module) requires you to also export the ReactiveFormsModule
to work.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
CommonModule,
ReactiveFormsModule
],
declarations: ,
exports: [
CommonModule,
FormsModule,
ReactiveFormsModule
]
})
export class SharedModule { }
edited Aug 22 '17 at 16:55
msanford
6,85164666
6,85164666
answered May 2 '17 at 11:18
UndriumUndrium
1,46911221
1,46911221
add a comment |
add a comment |
Ok after some digging I found a solution for "Can't bind to 'formGroup' since it isn't a known property of 'form'."
For my case, I've been using multiple modules files, i added ReactiveFormsModule in app.module.ts
import { FormsModule, ReactiveFormsModule } from '@angular/forms';`
@NgModule({
declarations: [
AppComponent,
]
imports: [
FormsModule,
ReactiveFormsModule,
AuthorModule,
],
...
But this wasn't working when I use a [formGroup] directive from a component added in another module, e.g. using [formGroup] in author.component.ts which is subscribed in author.module.ts file:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AuthorComponent } from './author.component';
@NgModule({
imports: [
CommonModule,
],
declarations: [
AuthorComponent,
],
providers: [...]
})
export class AuthorModule {}
I thought if i added ReactiveFormsModule in app.module.ts, by default ReactiveFormsModule would be inherited by all its children modules like author.module in this case... (wrong!).
I needed to import ReactiveFormsModule in author.module.ts in order to make all directives to work:
...
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
...
@NgModule({
imports: [
...,
FormsModule, //added here too
ReactiveFormsModule //added here too
],
declarations: [...],
providers: [...]
})
export class AuthorModule {}
So, if you are using submodules, make sure to import ReactiveFormsModule in each submodule file.
Hope this helps anyone.
2
Thank you for providing the story as well. This is exactly what I've wasted my time on for 2 days now...
– ntgCleaner
Aug 12 '18 at 18:33
1
Works for me, exactly the same problem, I really thought modules in exports array will be inherited by children modules... Don't know why exactly ! EDIT : documentation says exports is to make components, pipes, directives available in the TEMPLATE of any COMPONENT ()
– guy777
Nov 22 '18 at 21:24
1
Thank you! Thank you! Thank you! Thank you for the good explanation and the code. It finally works
– Kenji Elzerman
Jan 18 at 8:45
add a comment |
Ok after some digging I found a solution for "Can't bind to 'formGroup' since it isn't a known property of 'form'."
For my case, I've been using multiple modules files, i added ReactiveFormsModule in app.module.ts
import { FormsModule, ReactiveFormsModule } from '@angular/forms';`
@NgModule({
declarations: [
AppComponent,
]
imports: [
FormsModule,
ReactiveFormsModule,
AuthorModule,
],
...
But this wasn't working when I use a [formGroup] directive from a component added in another module, e.g. using [formGroup] in author.component.ts which is subscribed in author.module.ts file:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AuthorComponent } from './author.component';
@NgModule({
imports: [
CommonModule,
],
declarations: [
AuthorComponent,
],
providers: [...]
})
export class AuthorModule {}
I thought if i added ReactiveFormsModule in app.module.ts, by default ReactiveFormsModule would be inherited by all its children modules like author.module in this case... (wrong!).
I needed to import ReactiveFormsModule in author.module.ts in order to make all directives to work:
...
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
...
@NgModule({
imports: [
...,
FormsModule, //added here too
ReactiveFormsModule //added here too
],
declarations: [...],
providers: [...]
})
export class AuthorModule {}
So, if you are using submodules, make sure to import ReactiveFormsModule in each submodule file.
Hope this helps anyone.
2
Thank you for providing the story as well. This is exactly what I've wasted my time on for 2 days now...
– ntgCleaner
Aug 12 '18 at 18:33
1
Works for me, exactly the same problem, I really thought modules in exports array will be inherited by children modules... Don't know why exactly ! EDIT : documentation says exports is to make components, pipes, directives available in the TEMPLATE of any COMPONENT ()
– guy777
Nov 22 '18 at 21:24
1
Thank you! Thank you! Thank you! Thank you for the good explanation and the code. It finally works
– Kenji Elzerman
Jan 18 at 8:45
add a comment |
Ok after some digging I found a solution for "Can't bind to 'formGroup' since it isn't a known property of 'form'."
For my case, I've been using multiple modules files, i added ReactiveFormsModule in app.module.ts
import { FormsModule, ReactiveFormsModule } from '@angular/forms';`
@NgModule({
declarations: [
AppComponent,
]
imports: [
FormsModule,
ReactiveFormsModule,
AuthorModule,
],
...
But this wasn't working when I use a [formGroup] directive from a component added in another module, e.g. using [formGroup] in author.component.ts which is subscribed in author.module.ts file:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AuthorComponent } from './author.component';
@NgModule({
imports: [
CommonModule,
],
declarations: [
AuthorComponent,
],
providers: [...]
})
export class AuthorModule {}
I thought if i added ReactiveFormsModule in app.module.ts, by default ReactiveFormsModule would be inherited by all its children modules like author.module in this case... (wrong!).
I needed to import ReactiveFormsModule in author.module.ts in order to make all directives to work:
...
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
...
@NgModule({
imports: [
...,
FormsModule, //added here too
ReactiveFormsModule //added here too
],
declarations: [...],
providers: [...]
})
export class AuthorModule {}
So, if you are using submodules, make sure to import ReactiveFormsModule in each submodule file.
Hope this helps anyone.
Ok after some digging I found a solution for "Can't bind to 'formGroup' since it isn't a known property of 'form'."
For my case, I've been using multiple modules files, i added ReactiveFormsModule in app.module.ts
import { FormsModule, ReactiveFormsModule } from '@angular/forms';`
@NgModule({
declarations: [
AppComponent,
]
imports: [
FormsModule,
ReactiveFormsModule,
AuthorModule,
],
...
But this wasn't working when I use a [formGroup] directive from a component added in another module, e.g. using [formGroup] in author.component.ts which is subscribed in author.module.ts file:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AuthorComponent } from './author.component';
@NgModule({
imports: [
CommonModule,
],
declarations: [
AuthorComponent,
],
providers: [...]
})
export class AuthorModule {}
I thought if i added ReactiveFormsModule in app.module.ts, by default ReactiveFormsModule would be inherited by all its children modules like author.module in this case... (wrong!).
I needed to import ReactiveFormsModule in author.module.ts in order to make all directives to work:
...
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
...
@NgModule({
imports: [
...,
FormsModule, //added here too
ReactiveFormsModule //added here too
],
declarations: [...],
providers: [...]
})
export class AuthorModule {}
So, if you are using submodules, make sure to import ReactiveFormsModule in each submodule file.
Hope this helps anyone.
edited Dec 8 '17 at 13:18
Ciaran Bruen
3,690134965
3,690134965
answered Aug 16 '17 at 13:29
Ashutosh JhaAshutosh Jha
4,94842746
4,94842746
2
Thank you for providing the story as well. This is exactly what I've wasted my time on for 2 days now...
– ntgCleaner
Aug 12 '18 at 18:33
1
Works for me, exactly the same problem, I really thought modules in exports array will be inherited by children modules... Don't know why exactly ! EDIT : documentation says exports is to make components, pipes, directives available in the TEMPLATE of any COMPONENT ()
– guy777
Nov 22 '18 at 21:24
1
Thank you! Thank you! Thank you! Thank you for the good explanation and the code. It finally works
– Kenji Elzerman
Jan 18 at 8:45
add a comment |
2
Thank you for providing the story as well. This is exactly what I've wasted my time on for 2 days now...
– ntgCleaner
Aug 12 '18 at 18:33
1
Works for me, exactly the same problem, I really thought modules in exports array will be inherited by children modules... Don't know why exactly ! EDIT : documentation says exports is to make components, pipes, directives available in the TEMPLATE of any COMPONENT ()
– guy777
Nov 22 '18 at 21:24
1
Thank you! Thank you! Thank you! Thank you for the good explanation and the code. It finally works
– Kenji Elzerman
Jan 18 at 8:45
2
2
Thank you for providing the story as well. This is exactly what I've wasted my time on for 2 days now...
– ntgCleaner
Aug 12 '18 at 18:33
Thank you for providing the story as well. This is exactly what I've wasted my time on for 2 days now...
– ntgCleaner
Aug 12 '18 at 18:33
1
1
Works for me, exactly the same problem, I really thought modules in exports array will be inherited by children modules... Don't know why exactly ! EDIT : documentation says exports is to make components, pipes, directives available in the TEMPLATE of any COMPONENT ()
– guy777
Nov 22 '18 at 21:24
Works for me, exactly the same problem, I really thought modules in exports array will be inherited by children modules... Don't know why exactly ! EDIT : documentation says exports is to make components, pipes, directives available in the TEMPLATE of any COMPONENT ()
– guy777
Nov 22 '18 at 21:24
1
1
Thank you! Thank you! Thank you! Thank you for the good explanation and the code. It finally works
– Kenji Elzerman
Jan 18 at 8:45
Thank you! Thank you! Thank you! Thank you for the good explanation and the code. It finally works
– Kenji Elzerman
Jan 18 at 8:45
add a comment |
I have encountered this error during unit testing of a component (only during testing, within application it worked normally). The solution is to import ReactiveFormsModule
in .spec.ts
file:
// Import module
import { ReactiveFormsModule } from '@angular/forms';
describe('MyComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [MyComponent],
imports: [ReactiveFormsModule], // Also add it to 'imports' array
})
.compileComponents();
}));
});
Precisely the problem I was encountering. This solution worked perfectly!
– Bill Dagg
Feb 1 at 17:35
add a comment |
I have encountered this error during unit testing of a component (only during testing, within application it worked normally). The solution is to import ReactiveFormsModule
in .spec.ts
file:
// Import module
import { ReactiveFormsModule } from '@angular/forms';
describe('MyComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [MyComponent],
imports: [ReactiveFormsModule], // Also add it to 'imports' array
})
.compileComponents();
}));
});
Precisely the problem I was encountering. This solution worked perfectly!
– Bill Dagg
Feb 1 at 17:35
add a comment |
I have encountered this error during unit testing of a component (only during testing, within application it worked normally). The solution is to import ReactiveFormsModule
in .spec.ts
file:
// Import module
import { ReactiveFormsModule } from '@angular/forms';
describe('MyComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [MyComponent],
imports: [ReactiveFormsModule], // Also add it to 'imports' array
})
.compileComponents();
}));
});
I have encountered this error during unit testing of a component (only during testing, within application it worked normally). The solution is to import ReactiveFormsModule
in .spec.ts
file:
// Import module
import { ReactiveFormsModule } from '@angular/forms';
describe('MyComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [MyComponent],
imports: [ReactiveFormsModule], // Also add it to 'imports' array
})
.compileComponents();
}));
});
answered Nov 29 '17 at 18:19
xuhccxuhcc
1,2731519
1,2731519
Precisely the problem I was encountering. This solution worked perfectly!
– Bill Dagg
Feb 1 at 17:35
add a comment |
Precisely the problem I was encountering. This solution worked perfectly!
– Bill Dagg
Feb 1 at 17:35
Precisely the problem I was encountering. This solution worked perfectly!
– Bill Dagg
Feb 1 at 17:35
Precisely the problem I was encountering. This solution worked perfectly!
– Bill Dagg
Feb 1 at 17:35
add a comment |
The suggested answer did not work for me with Angular 4. Instead I had to use another way of attribute binding with the attr
prefix:
<element [attr.attribute-to-bind]="someValue">
2
Hey man! Are you sure your answer is related to the question? :) The question was about an issue setting up a form - cause by not properly setting up the ngModule
– FrancescoMussi
Apr 26 '17 at 14:24
@johnnyfittizio Pretty sure. Same scenario, same error message.
– str
Apr 26 '17 at 14:47
1
This worked for me, but is strange - why do I need theattr.
?
– CodyBugstein
Oct 26 '17 at 21:17
@CodyBugstein See angular.io/guide/template-syntax#attribute-binding
– str
Oct 27 '17 at 10:04
Thanks a ton. This worked for me also, but I would think there must be something else triggering the problem, like library versioning, or <form> tag positioning? Strange.
– Memetican
Mar 14 at 23:33
|
show 1 more comment
The suggested answer did not work for me with Angular 4. Instead I had to use another way of attribute binding with the attr
prefix:
<element [attr.attribute-to-bind]="someValue">
2
Hey man! Are you sure your answer is related to the question? :) The question was about an issue setting up a form - cause by not properly setting up the ngModule
– FrancescoMussi
Apr 26 '17 at 14:24
@johnnyfittizio Pretty sure. Same scenario, same error message.
– str
Apr 26 '17 at 14:47
1
This worked for me, but is strange - why do I need theattr.
?
– CodyBugstein
Oct 26 '17 at 21:17
@CodyBugstein See angular.io/guide/template-syntax#attribute-binding
– str
Oct 27 '17 at 10:04
Thanks a ton. This worked for me also, but I would think there must be something else triggering the problem, like library versioning, or <form> tag positioning? Strange.
– Memetican
Mar 14 at 23:33
|
show 1 more comment
The suggested answer did not work for me with Angular 4. Instead I had to use another way of attribute binding with the attr
prefix:
<element [attr.attribute-to-bind]="someValue">
The suggested answer did not work for me with Angular 4. Instead I had to use another way of attribute binding with the attr
prefix:
<element [attr.attribute-to-bind]="someValue">
edited Oct 27 '17 at 10:04
answered Apr 21 '17 at 11:30
strstr
18.6k65783
18.6k65783
2
Hey man! Are you sure your answer is related to the question? :) The question was about an issue setting up a form - cause by not properly setting up the ngModule
– FrancescoMussi
Apr 26 '17 at 14:24
@johnnyfittizio Pretty sure. Same scenario, same error message.
– str
Apr 26 '17 at 14:47
1
This worked for me, but is strange - why do I need theattr.
?
– CodyBugstein
Oct 26 '17 at 21:17
@CodyBugstein See angular.io/guide/template-syntax#attribute-binding
– str
Oct 27 '17 at 10:04
Thanks a ton. This worked for me also, but I would think there must be something else triggering the problem, like library versioning, or <form> tag positioning? Strange.
– Memetican
Mar 14 at 23:33
|
show 1 more comment
2
Hey man! Are you sure your answer is related to the question? :) The question was about an issue setting up a form - cause by not properly setting up the ngModule
– FrancescoMussi
Apr 26 '17 at 14:24
@johnnyfittizio Pretty sure. Same scenario, same error message.
– str
Apr 26 '17 at 14:47
1
This worked for me, but is strange - why do I need theattr.
?
– CodyBugstein
Oct 26 '17 at 21:17
@CodyBugstein See angular.io/guide/template-syntax#attribute-binding
– str
Oct 27 '17 at 10:04
Thanks a ton. This worked for me also, but I would think there must be something else triggering the problem, like library versioning, or <form> tag positioning? Strange.
– Memetican
Mar 14 at 23:33
2
2
Hey man! Are you sure your answer is related to the question? :) The question was about an issue setting up a form - cause by not properly setting up the ngModule
– FrancescoMussi
Apr 26 '17 at 14:24
Hey man! Are you sure your answer is related to the question? :) The question was about an issue setting up a form - cause by not properly setting up the ngModule
– FrancescoMussi
Apr 26 '17 at 14:24
@johnnyfittizio Pretty sure. Same scenario, same error message.
– str
Apr 26 '17 at 14:47
@johnnyfittizio Pretty sure. Same scenario, same error message.
– str
Apr 26 '17 at 14:47
1
1
This worked for me, but is strange - why do I need the
attr.
?– CodyBugstein
Oct 26 '17 at 21:17
This worked for me, but is strange - why do I need the
attr.
?– CodyBugstein
Oct 26 '17 at 21:17
@CodyBugstein See angular.io/guide/template-syntax#attribute-binding
– str
Oct 27 '17 at 10:04
@CodyBugstein See angular.io/guide/template-syntax#attribute-binding
– str
Oct 27 '17 at 10:04
Thanks a ton. This worked for me also, but I would think there must be something else triggering the problem, like library versioning, or <form> tag positioning? Strange.
– Memetican
Mar 14 at 23:33
Thanks a ton. This worked for me also, but I would think there must be something else triggering the problem, like library versioning, or <form> tag positioning? Strange.
– Memetican
Mar 14 at 23:33
|
show 1 more comment
If you have to import two modules then add like this below
import {ReactiveFormsModule,FormsModule} from '@angular/forms';
@NgModule({
declarations: [
AppComponent,
HomeComponentComponent,
BlogComponentComponent,
ContactComponentComponent,
HeaderComponentComponent,
FooterComponentComponent,
RegisterComponent,
LoginComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
routes,
ReactiveFormsModule
],
providers: ,
bootstrap: [AppComponent]
})
add a comment |
If you have to import two modules then add like this below
import {ReactiveFormsModule,FormsModule} from '@angular/forms';
@NgModule({
declarations: [
AppComponent,
HomeComponentComponent,
BlogComponentComponent,
ContactComponentComponent,
HeaderComponentComponent,
FooterComponentComponent,
RegisterComponent,
LoginComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
routes,
ReactiveFormsModule
],
providers: ,
bootstrap: [AppComponent]
})
add a comment |
If you have to import two modules then add like this below
import {ReactiveFormsModule,FormsModule} from '@angular/forms';
@NgModule({
declarations: [
AppComponent,
HomeComponentComponent,
BlogComponentComponent,
ContactComponentComponent,
HeaderComponentComponent,
FooterComponentComponent,
RegisterComponent,
LoginComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
routes,
ReactiveFormsModule
],
providers: ,
bootstrap: [AppComponent]
})
If you have to import two modules then add like this below
import {ReactiveFormsModule,FormsModule} from '@angular/forms';
@NgModule({
declarations: [
AppComponent,
HomeComponentComponent,
BlogComponentComponent,
ContactComponentComponent,
HeaderComponentComponent,
FooterComponentComponent,
RegisterComponent,
LoginComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
routes,
ReactiveFormsModule
],
providers: ,
bootstrap: [AppComponent]
})
edited Mar 11 at 5:37
answered May 27 '17 at 8:59
sudheer nunnasudheer nunna
46159
46159
add a comment |
add a comment |
Keep in mind that if you have defined "Feature Modules", you'll need to import in the Feature Module, even if you already imported to the AppModule
. From the Angular documentation:
Modules don't inherit access to the components, directives, or pipes that are declared in other modules. What AppModule imports is irrelevant to ContactModule and vice versa. Before ContactComponent can bind with [(ngModel)], its ContactModule must import FormsModule.
https://angular.io/docs/ts/latest/guide/ngmodule.html
add a comment |
Keep in mind that if you have defined "Feature Modules", you'll need to import in the Feature Module, even if you already imported to the AppModule
. From the Angular documentation:
Modules don't inherit access to the components, directives, or pipes that are declared in other modules. What AppModule imports is irrelevant to ContactModule and vice versa. Before ContactComponent can bind with [(ngModel)], its ContactModule must import FormsModule.
https://angular.io/docs/ts/latest/guide/ngmodule.html
add a comment |
Keep in mind that if you have defined "Feature Modules", you'll need to import in the Feature Module, even if you already imported to the AppModule
. From the Angular documentation:
Modules don't inherit access to the components, directives, or pipes that are declared in other modules. What AppModule imports is irrelevant to ContactModule and vice versa. Before ContactComponent can bind with [(ngModel)], its ContactModule must import FormsModule.
https://angular.io/docs/ts/latest/guide/ngmodule.html
Keep in mind that if you have defined "Feature Modules", you'll need to import in the Feature Module, even if you already imported to the AppModule
. From the Angular documentation:
Modules don't inherit access to the components, directives, or pipes that are declared in other modules. What AppModule imports is irrelevant to ContactModule and vice versa. Before ContactComponent can bind with [(ngModel)], its ContactModule must import FormsModule.
https://angular.io/docs/ts/latest/guide/ngmodule.html
answered May 5 '17 at 12:42
Ian GriffinIan Griffin
10114
10114
add a comment |
add a comment |
I had the same issue with Angular 7. Just import following in your app.module.ts file.
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Then add FormsModule and ReactiveFormsModule in to your imports array.
imports: [
FormsModule,
ReactiveFormsModule
],
add a comment |
I had the same issue with Angular 7. Just import following in your app.module.ts file.
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Then add FormsModule and ReactiveFormsModule in to your imports array.
imports: [
FormsModule,
ReactiveFormsModule
],
add a comment |
I had the same issue with Angular 7. Just import following in your app.module.ts file.
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Then add FormsModule and ReactiveFormsModule in to your imports array.
imports: [
FormsModule,
ReactiveFormsModule
],
I had the same issue with Angular 7. Just import following in your app.module.ts file.
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Then add FormsModule and ReactiveFormsModule in to your imports array.
imports: [
FormsModule,
ReactiveFormsModule
],
edited Feb 27 at 6:15
answered Jan 4 at 4:34
Chamila MaddumageChamila Maddumage
7281922
7281922
add a comment |
add a comment |
This problem occurs due to missing import of FormsModule,ReactiveFormsModule .I also came with same problem.
My case was diff. as i was working with modules.So i missed above imports in my parent modules though i had imported it into child modules,it wasn't working.
Then i imported it into my parent modules as below, and it worked!
import { ReactiveFormsModule,FormsModule } from '@angular/forms';
import { AlertModule } from 'ngx-bootstrap';
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
],
declarations: [MyComponent]
})
add a comment |
This problem occurs due to missing import of FormsModule,ReactiveFormsModule .I also came with same problem.
My case was diff. as i was working with modules.So i missed above imports in my parent modules though i had imported it into child modules,it wasn't working.
Then i imported it into my parent modules as below, and it worked!
import { ReactiveFormsModule,FormsModule } from '@angular/forms';
import { AlertModule } from 'ngx-bootstrap';
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
],
declarations: [MyComponent]
})
add a comment |
This problem occurs due to missing import of FormsModule,ReactiveFormsModule .I also came with same problem.
My case was diff. as i was working with modules.So i missed above imports in my parent modules though i had imported it into child modules,it wasn't working.
Then i imported it into my parent modules as below, and it worked!
import { ReactiveFormsModule,FormsModule } from '@angular/forms';
import { AlertModule } from 'ngx-bootstrap';
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
],
declarations: [MyComponent]
})
This problem occurs due to missing import of FormsModule,ReactiveFormsModule .I also came with same problem.
My case was diff. as i was working with modules.So i missed above imports in my parent modules though i had imported it into child modules,it wasn't working.
Then i imported it into my parent modules as below, and it worked!
import { ReactiveFormsModule,FormsModule } from '@angular/forms';
import { AlertModule } from 'ngx-bootstrap';
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
],
declarations: [MyComponent]
})
answered Apr 11 '18 at 9:59
SauravSaurav
25633
25633
add a comment |
add a comment |
For people strolling these threads about this error. In my case I had a shared module where I only exported the FormsModule and ReactiveFormsModule and forgot to import it. This caused a strange error that formgroups were not working in sub components. Hope this helps people scratching their heads.
add a comment |
For people strolling these threads about this error. In my case I had a shared module where I only exported the FormsModule and ReactiveFormsModule and forgot to import it. This caused a strange error that formgroups were not working in sub components. Hope this helps people scratching their heads.
add a comment |
For people strolling these threads about this error. In my case I had a shared module where I only exported the FormsModule and ReactiveFormsModule and forgot to import it. This caused a strange error that formgroups were not working in sub components. Hope this helps people scratching their heads.
For people strolling these threads about this error. In my case I had a shared module where I only exported the FormsModule and ReactiveFormsModule and forgot to import it. This caused a strange error that formgroups were not working in sub components. Hope this helps people scratching their heads.
answered Oct 18 '17 at 8:20
GKooijGKooij
5111
5111
add a comment |
add a comment |
I was coming across this error when trying to do e2e testing and it was driving me crazy that there were no answers to this.
IF YOU ARE DOING TESTING, find your *.specs.ts file and add :
import {ReactiveFormsModule, FormsModule} from '@angular/forms';
add a comment |
I was coming across this error when trying to do e2e testing and it was driving me crazy that there were no answers to this.
IF YOU ARE DOING TESTING, find your *.specs.ts file and add :
import {ReactiveFormsModule, FormsModule} from '@angular/forms';
add a comment |
I was coming across this error when trying to do e2e testing and it was driving me crazy that there were no answers to this.
IF YOU ARE DOING TESTING, find your *.specs.ts file and add :
import {ReactiveFormsModule, FormsModule} from '@angular/forms';
I was coming across this error when trying to do e2e testing and it was driving me crazy that there were no answers to this.
IF YOU ARE DOING TESTING, find your *.specs.ts file and add :
import {ReactiveFormsModule, FormsModule} from '@angular/forms';
answered Nov 3 '17 at 13:03
Mr GigglesMr Giggles
486515
486515
add a comment |
add a comment |
A LITTLE NOTE: Be careful about loaders and minimize (Rails env.):
After seeing this error and trying every solution out there, i realised there was something wrong with my html loader.
I've set my Rails environment up to import HTML paths for my components successfully with this loader (config/loaders/html.js.
):
module.exports = {
test: /.html$/,
use: [ {
loader: 'html-loader?exportAsEs6Default',
options: {
minimize: true
}
}]
}
After some hours efforts and countless of ReactiveFormsModule imports i saw that my formGroup
was small letters: formgroup
.
This led me to the loader and the fact that it downcased my HTML on minimize.
After changing the options, everything worked as it should, and i could go back to crying again.
I know that this is not an answer to the question, but for future Rails visitors (and other with custom loaders) i think this could be helpfull.
add a comment |
A LITTLE NOTE: Be careful about loaders and minimize (Rails env.):
After seeing this error and trying every solution out there, i realised there was something wrong with my html loader.
I've set my Rails environment up to import HTML paths for my components successfully with this loader (config/loaders/html.js.
):
module.exports = {
test: /.html$/,
use: [ {
loader: 'html-loader?exportAsEs6Default',
options: {
minimize: true
}
}]
}
After some hours efforts and countless of ReactiveFormsModule imports i saw that my formGroup
was small letters: formgroup
.
This led me to the loader and the fact that it downcased my HTML on minimize.
After changing the options, everything worked as it should, and i could go back to crying again.
I know that this is not an answer to the question, but for future Rails visitors (and other with custom loaders) i think this could be helpfull.
add a comment |
A LITTLE NOTE: Be careful about loaders and minimize (Rails env.):
After seeing this error and trying every solution out there, i realised there was something wrong with my html loader.
I've set my Rails environment up to import HTML paths for my components successfully with this loader (config/loaders/html.js.
):
module.exports = {
test: /.html$/,
use: [ {
loader: 'html-loader?exportAsEs6Default',
options: {
minimize: true
}
}]
}
After some hours efforts and countless of ReactiveFormsModule imports i saw that my formGroup
was small letters: formgroup
.
This led me to the loader and the fact that it downcased my HTML on minimize.
After changing the options, everything worked as it should, and i could go back to crying again.
I know that this is not an answer to the question, but for future Rails visitors (and other with custom loaders) i think this could be helpfull.
A LITTLE NOTE: Be careful about loaders and minimize (Rails env.):
After seeing this error and trying every solution out there, i realised there was something wrong with my html loader.
I've set my Rails environment up to import HTML paths for my components successfully with this loader (config/loaders/html.js.
):
module.exports = {
test: /.html$/,
use: [ {
loader: 'html-loader?exportAsEs6Default',
options: {
minimize: true
}
}]
}
After some hours efforts and countless of ReactiveFormsModule imports i saw that my formGroup
was small letters: formgroup
.
This led me to the loader and the fact that it downcased my HTML on minimize.
After changing the options, everything worked as it should, and i could go back to crying again.
I know that this is not an answer to the question, but for future Rails visitors (and other with custom loaders) i think this could be helpfull.
answered May 22 '18 at 15:44
Peter Højlund AndersenPeter Højlund Andersen
425416
425416
add a comment |
add a comment |
Can't bind to 'formGroup' since it isn't a known property of 'form'
means that you try to bind a property using angular ([prop]
) but angular cant find anything he knows for that element (in this case form
).
this can happen by not using the right module (missing an import somewhere in the way) and sometimes just cause a typo like:
[formsGroup]
, with s
after form
add a comment |
Can't bind to 'formGroup' since it isn't a known property of 'form'
means that you try to bind a property using angular ([prop]
) but angular cant find anything he knows for that element (in this case form
).
this can happen by not using the right module (missing an import somewhere in the way) and sometimes just cause a typo like:
[formsGroup]
, with s
after form
add a comment |
Can't bind to 'formGroup' since it isn't a known property of 'form'
means that you try to bind a property using angular ([prop]
) but angular cant find anything he knows for that element (in this case form
).
this can happen by not using the right module (missing an import somewhere in the way) and sometimes just cause a typo like:
[formsGroup]
, with s
after form
Can't bind to 'formGroup' since it isn't a known property of 'form'
means that you try to bind a property using angular ([prop]
) but angular cant find anything he knows for that element (in this case form
).
this can happen by not using the right module (missing an import somewhere in the way) and sometimes just cause a typo like:
[formsGroup]
, with s
after form
edited Jan 5 '18 at 12:55
answered Nov 17 '17 at 8:55
bresleveloperbresleveloper
4,08932340
4,08932340
add a comment |
add a comment |
protected by Günter Zöchbauer Oct 18 '17 at 8:21
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?