-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Can't use a <form> tag with a [formControl] directive #38391
Comments
@kara Nice to hear from you again. 🥰
Yep, it's a bit hidden feature, but still, even with this directive, the console prints |
…tusGroup` directive The `NgControlStatusGroup` directive is shared between template-driven and reactive form modules. In cases when only reactive forms module is present, the `NgControlStatusGroup` directive is still activated on all `<form>` elements, but if there is no other reactive directive applied (such as `formGroup`), corresponding `ControlContainer` itoken is missing, thus causing exceptions (since `NgControlStatusGroup` directive relies on it to determine the status). This commit updates the logic to handle the case when no `ControlContainer` is present (effectively making directive logic a noop in this case). Alternative approach (more risky) worth considering in the future is to split the `NgControlStatusGroup` into 2 directives with different set of selectors and include them into template-driven and reactive modules separately. The downside is that these directives might be activated simultaneously on the same element (e.g. `<form>`), effectively doing the work twice. Resolves angular#38391.
…tusGroup` directive The `NgControlStatusGroup` directive is shared between template-driven and reactive form modules. In cases when only reactive forms module is present, the `NgControlStatusGroup` directive is still activated on all `<form>` elements, but if there is no other reactive directive applied (such as `formGroup`), corresponding `ControlContainer` token is missing, thus causing exceptions (since `NgControlStatusGroup` directive relies on it to determine the status). This commit updates the logic to handle the case when no `ControlContainer` is present (effectively making directive logic a noop in this case). Alternative approach (more risky) worth considering in the future is to split the `NgControlStatusGroup` into 2 directives with different set of selectors and include them into template-driven and reactive modules separately. The downside is that these directives might be activated simultaneously on the same element (e.g. `<form>`), effectively doing the work twice. Resolves angular#38391.
…tusGroup` directive (#40344) The `NgControlStatusGroup` directive is shared between template-driven and reactive form modules. In cases when only reactive forms module is present, the `NgControlStatusGroup` directive is still activated on all `<form>` elements, but if there is no other reactive directive applied (such as `formGroup`), corresponding `ControlContainer` token is missing, thus causing exceptions (since `NgControlStatusGroup` directive relies on it to determine the status). This commit updates the logic to handle the case when no `ControlContainer` is present (effectively making directive logic a noop in this case). Alternative approach (more risky) worth considering in the future is to split the `NgControlStatusGroup` into 2 directives with different set of selectors and include them into template-driven and reactive modules separately. The downside is that these directives might be activated simultaneously on the same element (e.g. `<form>`), effectively doing the work twice. Resolves #38391. PR Close #40344
@kara thanks for reporting the issue! The fix was merged and it's now available in google3 :) |
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. |
🐞 bug report
Affected Package
The issue is caused by package angular/forms.
Is this a regression?
I don't think this is new behavior
Description
It's not currently possible to wrap a
[formControl]
directive in a<form>
tag because an error is thrown byNgControlStatusGroup
that theControlContainer
is missing. This isn't right because[formControl]
directives are intended to be used without aControlContainer
.The problem seems to be caused by
NgControlStatusGroup
having too broad of a selector, so that it activates on allform
tags.Workarounds:
ngNoForm
to the parent<form>
tag, but that is not intuitiveFormsModule
soNgForm
is automatically created. However, this isn't really correct because it requires mixing the forms modules.🔬 Minimal Reproduction
https://stackblitz.com/edit/angular-ivy-cke9q5?file=src%2Fapp%2Fapp.component.html
If you load that Stackblitz, you can see the error in the console.
🔥 Exception or Error
🌍 Your Environment
Angular Version:
Ivy, v10
The text was updated successfully, but these errors were encountered: