-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Injected ngControl doesn't contain control property in Angular 9 #35330
Comments
Listen to opDisabled input binding change inside ngOnChanges, In this way you can fix this issue.
For More Information Check this thread: https://twitter.com/yurzui/status/1225050458097704960 |
@ChellappanRajan thanks. This looks awkward, nevertheless. |
So will this issue be fixed, or is the ngOnChanges workaround going to be required for Ivy permanently? |
So which solution is actually better? the setTimeout or ngOnChanges solution? |
There are more missing properties/values when injecting With directive like: @Directive({
selector: '[appTest]',
providers: [NgModel]
})
export class TestDirective implements OnInit{
constructor(
private ngModel: NgModel
) { }
ngOnInit(): void {
console.log(this.ngModel);
}
} Used like this: <form>
<input type="text" name="test-input" [(ngModel)]="title" appTest>
</form> On Angular 9
On Angular 8
In other words, at least Disabling Ivy in
|
Minimal reproduce scenario without using Material components: https://stackblitz.com/edit/angular-duxmqt?file=src%2Fapp%2Fapp.module.ts |
Here is the example impl: https://stackblitz.com/edit/angular-xeaqyy?file=src/app/app.module.ts
So this is a tricky one. The current confusing behaviour is ivy is a combination of 2 implementations choices in forms and Angular core:
The above explains the error but this explanation only "make sense" if ones is familiar with the internal implementation and can be quite confusing for users. We are still debatting the best approach here, for now the safest option is to go down the |
Is there some documentation that can be updated (maybe even the JSDocs) until this odd behavior is fixed? I forgot to implement this in some new code and had to go looking up this error again, only to find I've commented before 😬 |
Hi all, got the same issue in a Directive used in a ReactiveForm input that in angular <= 8 used to work but with version 9+ the injected formControlName instance is missing name and control attributes. fixed using the valueAccessor attribute of the injected FormControlName instance (because name and control are now undefined)
HTH |
Is there any news on this topic? |
@zakharenkov @micobarac if you are using |
🐞 bug report
Affected Package
import { NgControl } from '@angular/forms';
Is this a regression?
I believe that this is an Ivy compiler issue
Description
Injected
ngControl
doesn't containcontrol
property in Angular 9.🔬 Minimal Reproduction
This doesn't work:
This works:
🔥 Exception or Error
The
control
property isundefined
and It looks like the it gets appended asynchronously to the injectedngControl
, that's why thesetTimeout(() => {...})
workaround seems to work. Is this by design or is it a bug?There is a similar issue reported #32522, but locked due to inactivity, without any solutions mentioned in the comments.
🌍 Your Environment
Angular Version:
The text was updated successfully, but these errors were encountered: