angular: Reactive Forms + AOT in 5.0.0-beta.7 - StaticInjectorError: No provider for NgForm
I’m submitting a…
[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
When compiling an App with Reactive Forms using AOT in 5.0.0-beta.7 i’m getting the following Error when navigating to the Form:
Expected behavior
Reactive Forms should work like in beta.6
Minimal reproduction of the problem with instructions
test.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { TestComponent } from './test.component';
@NgModule({
declarations: [ TestComponent ],
imports: [ CommonModule, ReactiveFormsModule ],
exports: [ TestComponent ],
providers: [],
})
export class TestModule {}
test.component.ts
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
@Component({
selector: 'app-form',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
form: FormGroup;
constructor() { }
ngOnInit() {
this.form = new FormGroup({
name: new FormControl('test')
});
}
}
test.component.html
<form [formGroup]="form">
<input type="text" formControlName="name">
</form>
What is the motivation / use case for changing the behavior?
Environment
Angular version: 5.0.0-beta.7
Browser:
- [x] Chrome (desktop) version 63
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [x] Safari (desktop) version 10.1.2
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: XX
- Platform:
Others:
@angular/cli: 1.5.0-beta.0
node: 7.5.0
os: darwin x64
@angular/animations: 5.0.0-beta.7
@angular/common: 5.0.0-beta.7
@angular/compiler: 5.0.0-beta.7
@angular/core: 5.0.0-beta.7
@angular/forms: 5.0.0-beta.7
@angular/http: 5.0.0-beta.7
@angular/platform-browser: 5.0.0-beta.7
@angular/platform-browser-dynamic: 5.0.0-beta.7
@angular/router: 5.0.0-beta.7
@angular/cli: 1.5.0-beta.0
@angular/compiler-cli: 5.0.0-beta.7
@angular/language-service: 5.0.0-beta.7
typescript: 2.4.2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 34
- Comments: 44 (12 by maintainers)
Commits related to this issue
- fix(tsc-wrapped): de-duplicate metadata only when the module is the same Fixes #19219 — committed to ocombe/angular by ocombe 7 years ago
- fix(tsc-wrapped): deduplicate metadata only when the module is the same Fixes #19219 — committed to ocombe/angular by ocombe 7 years ago
- fix(tsc-wrapped): deduplicate metadata only when the module is the same Fixes #19219 — committed to ocombe/angular by ocombe 7 years ago
- fix(tsc-wrapped): deduplicate metadata only when the module is the same (#19249) Fixes #19219 PR Close #19249 — committed to mahak/angular by ocombe 7 years ago
- fix(tsc-wrapped): deduplicate metadata only when the module is the same Fixes #19219 — committed to ocombe/angular by ocombe 7 years ago
- fix(tsc-wrapped): deduplicate metadata only when the module is the same Fixes #19219 — committed to ocombe/angular by ocombe 7 years ago
- fix(tsc-wrapped): deduplicate metadata only when the module is the same Fixes #19219 — committed to ocombe/angular by ocombe 7 years ago
- fix(tsc-wrapped): deduplicate metadata only when the module is the same (#19261) Fixes #19219 PR Close #19261 — committed to angular/angular by ocombe 7 years ago
- Updated Angular to fix Forms issue in prod mode. See https://github.com/angular/angular/issues/19219#issuecomment-330431900 — committed to ripvanbl/pitpass-generator by ripvanbl 7 years ago
yes 4.4.2 doesn’t include this patch because we had problems with our CI, we’ll have another release 4.4.3 today with it… sorry about that
Not sure if it’s the same bug, but I’m seeing the same error after upgrading from 4.3.6 to 4.4.1.
4.4.3 is out
The release will probably happen later today. Sorry for the glitch !
Can confirm this for v4.4.1 only when running in AOT To Reproduce
ng new noformprovider
Replce app.component.ts withng serve --aot
open up browser and inspect console for error:Thanks @alexzuza for tracking the root cause. Working on a fix right now.
I cherry-picked the fix for the into the 4.4.x branch and I’m about to cut the 4.4.3 release that will resolve this problem.
I think I got the same for 4.2.x For those who don’t know how to set 4.3.6 i did :
and it worked for me 😃 (checked with “ng -v”)
hope it helped.
Same here with 4.4.1 and AOT using
[formControl]="myFormControl"
throwsNo provider for NgModel!
and[formGroup]="myForm"
throwsNo provider for NgForm!
With 4.3.6 all is working.
@IgorMinar Can the fix be made to the 5.0.0-beta.x branch as well?
Verified that this works fine in
4.3.6
, but is broken in4.4.1
. I feel like a unit test should’ve caught this before a release.Yeah same here in 4.4.1. I’ve reverted to 4.3.6 and that’s ok.
Same here in 4.4.1
This still doesn’t appear to be fixed in the 5.x branch. Coming soon?
👍 same here, just updated to 4.4.1
I am experiencing this same ‘No provider for e!’ error on v5.2.7. Any ideas?
I can confirm that v4.4.3 fixed the issue as well.
@IgorMinar 4.4.3 fixed the issue for me. Thanks!
@feelthescintillation … it should be 4.4.3.
The same on 5.2.9
There has been a report in Angular CLI of another library that suffered from this problem with Angular v5 (https://github.com/angular/angular-cli/issues/9383, more info in https://github.com/psykolm22/angular-google-place/issues/29#issuecomment-360884843). Maybe this is still a problem.
I had the same issue with 4.2.4 version. I’ve just made next steps:
npm i
oryarn
;and it works now. Thanks for everyone!
@maximebourdel Because
^4.2.6
will install4.4.2
and~4.3.6
will install4.3.6
. You can read more about caret ranges and other specifications and use tester to play with it.@TahaDiNero I don’t know when we will release a new version with the fix, it’ll be this week but not sure which day yet
I think the problem here is
forms.metadata.json
that angular published on npmLet’s see why…
I compared jit and aot code generated by angular 5.0.0-beta.7. Angular generates wrong reference to ControlContainer provider(
useExisting
) forFormGroupDirective
jit
aot
Then i investigated how angular gets reference and found out the following
forms.metadata.json angular 4.3.6
forms.metadata.json angular since 4.4.x
where
ɵe
form.d.ts
I think it can be related with the fact that
NgForm
directive declares provider with the same name asFormGroupDirective
https://github.com/angular/angular/blob/5.0.0-beta.7/packages/forms/src/directives/ng_form.ts#L21-L25