-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Can't bind to 'formGroup' since it isn't a known property of 'form' #14288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
did you import |
@DzmitryShylovich: I did, I mentioned it with the reproduction steps as well.
|
Pls add a plunkr with repro |
Ï will, out of time at the moment though, I will add it first thing tomorrow morning. You haven't been able to repro it with angular-cli at your end then? |
Nope, I can't reproduce using cli |
works for me using the latest version with the cli - nevertheless, ng-test fails with that very same error - I tried to stub it, but no change - any hints? |
@DzmitryShylovich Sigh. Miraculously, everything today suddenly decided to work. Generated another new project and followed the same steps, no problems. Copied code from yesterday's project, no problems. Never mind I guess. Crisis averted. Thanks anyway though. Should I run into it again, I'll let you know. @jorgjanke: Did you declare the
|
@JPtenBerge 👍 close the issue then pls. thx |
Hey this issue shouldn't be closed yet. The same error is being raised with version 2.4.8 and non of your solutions are helping. |
Im getting the same error in version 2.4.8 component.ts file seems to recongnize FormGroup, FormControl, FormBuilder, Validators, but using [formGroup] inside component.html file throws same error: "Can't bind to 'formGroup' since it isn't a known property of 'form'." |
Getting the same problem with 2.4.8. After some debugging/trial and error I found that Validators are breaking my code: This throws the 'Can't bind to 'formGroup' since it isn't a known property of 'form'' - error:
while this does not throw an error:
So there seems to be a change in way validators are passed or some methods are no longer available or something. The error is very vague and only exposes itself as a template parse error. I will check the latest docs on validation though. |
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
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:
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!).
So, if you are using submodules, make sure to import ReactiveFormsModule in each submodule file. |
Yup, there are no global directives. If components use components, directives, or pipes, the module they are part of need to import these components, directives, or pipes. Only services provided by modules imported to GitHub issues are for bug reports and feature requests. |
After upgrading angular2 to new version i face similar issue. After lot of changes i got it to work by updating the followings in src/polyfills.ts file. import 'core-js/es6/symbol'; |
Any solutions to this yet? Running my app is just fine but it's in the spec files I'm having issues. I'm importing ReactiveFormsModule into the TestBed but still, no dice. |
Followed @Matfork and it works, must import both FormsModule, ReactiveFormsModule . |
I'm in the same boat as @Marcidius |
Let me give some details. This problem only occurs running Visual Studio 2017 latest Angular 4 template. They've got multiple modules for client, server, shared. The only way I got it to work in this envioronment was to import the ReactiveFormsModule directly into the component that needed it and changing [formgroup] to (formgroup) I just tested installing angular/cli and creating a new project from template and it worked as normally expected. I would say that the problem is with the Visual Studio template I'm using and the way it has framed up their modules. |
Update, just found out that the problem was with the spa template I was using. They will be correcting the issue in an update. The work around is to import FormsModule and ReactiveFormsModue into both the app.module.client and app.module.server. |
@Phillippe43 by doing this, you're changing property binding to event binding which changes the purpose in whole |
Getting same error in Angular 4.2.1 also |
@Phillippe43 Thanks, adding the import to both the app.module.client and app.module.server worked for me |
I had the same trouble as @rjsteinert and @Marcidius. In my spec I had to add the header import as well as the test bed import. Hope it helps.
|
I know this is very late, but I found this issue while searching for an answer to binding properties for custom components in a shared module. In my case the problem was that my lazy loaded page was still included in the app.module.ts file. Removing that fixed the Can't bind to 'xxx' since it isn't a known property. Just putting this up for anyone else facing the same issue. It's really just the error message has nothing to do with the actual solution. |
I had this also. I had to manually refresh the page after adding ReactiveFormsModule to the imports for my module before I could see the change. LiveReload didn't work. |
Imports this line in the module, which declared that component. import { ReactiveFormsModule, FormsModule } from '@angular/forms'; Example: write this line: import { ReactiveFormsModule, FormsModule } from '@angular/forms'; Thanks & Regards, |
The first time I got this error was because I did: [FormGroup] instead of [formGroup] since I was creating it as a new new FormGroup in the component. Making the f lower case fixed it. |
@ctscodes You are the true hero! |
So why is [form-group] not allowed as an attribute value (making the attribute dashed and lowercase). I thought that would be the same as [formGroup] but apparently the error pops up too if you try it |
ctscodes replays awasome that also works for me thanks ctscodes:) |
same problem here. |
One solution ist :
app.module.ts
And the component code look like
It works pretty good 💯 |
Followed @Matfork and it works, must import both FormsModule, ReactiveFormsModule . |
your answer worked partially in my case. |
So fiddling around with the same frustrating issue -- a clean angular-cli install and a custom subcomponent/module (component.html... <form [formGroup]="demoForm" (ngSubmit)="onSubmit()">) and the same error ("Can't bind to 'formGroup' since it isn't a known property of 'form' "). I finally got it to work based on the above but with a twist
Afterward ng build/serve worked without any errors. I'm not an Angular expert but my guess is that the v7 approach whereby app.module.ts delegates to app-routing, that latter file is where the app & component imports & dependencies take place.... YMMV but hopefully it helps. |
LIKE A CHARM!!!! |
For making this work you need to |
lol !! you were the one who dropped out this same comment on stack overflow :p |
This helped me. I created my app with AppRouting. It looks like all of the components are created by the AppRouting Module. I had to add ReactiveFormsModule to the AppRouting Module. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a ...
Current behavior
Simply using the
[formGroup]
directive when everything has been setup properly results in the error above.Expected behavior
The
formGroup
was one of the most basic directives to use when working with Reactive Forms. It tied a form element to the definition of the form (residing in a component). I expect no error. I've used[formGroup]
since 2.0.0-RC5 (I think) and the documentation still says it should work like this, but it doesn't.Minimal reproduction of the problem with instructions
@angular/cli
, create a new project.FormsModule
toReactiveFormsModule
(two places).Running the application will now result in the error:
Can't bind to 'formGroup' since it isn't a known property of 'form'.
What is the motivation / use case for changing the behavior?
Basic reactive forms are not working properly anymore.
Please tell us about your environment:
Windows 10 64 bit. Created the project with @angular/cli v1.0.0-beta.30
Angular version: 2.3.1 (latest)
Browser: all: Chrome 55, Firefox, Internet Explorer 11, Edge 38
Language: TypeScript 2.0.3
Node (for AoT issues):
node --version
= 7.5.0The text was updated successfully, but these errors were encountered: