-
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
Supporting [formArray] without a [formGroup] parent #30264
Comments
@WreckItRalph ... what is the advantage of that? Why do you suggest that at all? |
@mlc-mlapis There might be scenarios where the form that needs to be created is a formArray and does not need a container, like submitting a list of { name, email}. In current scenario, it would look something like : It would be better if it could be just the array: |
@WreckItRalph ... yep, I can see that theoretical case but in reality, I have never met it. |
Well.. I have met and hence the suggestion. It would be good to have. |
It's needed, main use case for me are completely dynamic forms. |
It's needed. I've met it too. But I found a solution myself. I create a FromArray into FormControl of FormGroup and then send it to server by accessing formControlName you know there I have a full array. So it's like |
I have multiple places in the current application I am working on where this would be beneficial. As a hacky work around, I am using *ngFor to iterate over the FormArray's controls, then binding them w/the [formGroup] directive. This works, but it's certainly not ideal. |
It's actually needed. Same problem as @nexxado, I had to wrap it in a FormGroup. |
Could we bind the [formGroup] to an ng-container ? |
@blemaire Sure. |
I had this problem as well. I agree on that this would be useful to have. |
This is NOT a theoretical use case ein fact we encounter it every day. Here is the simple version of the use case:
By having a
|
Yes, my use case aligns with this |
same use case as @ntziolis. Is this a feature you're working on or going to work on in near future? Or is there any workaround to pass formArrays into sub components without the need to pass the reference to the parent group? |
I have the same use case as @ntziolis as well. |
Totally agree with the described use cases. I needed this a bunch of times myself, and would love to finally see a real For what it's worth, though, you can also pass a <form [formGroup]="$any(formArray)" *ngFor="let entry of formArray.controls; let i = index">
<input [formControlName]="i">
</form> |
I needed this a bunch of times myself, and would love to finally see a real [formArray] directive! (2) |
omg where that [formArray] directive!!!! for god! we need that |
we need it |
Oh come on, this is common knowledge. Bumping for support. |
And then let's bump it again! NEEDED! 😠 |
Of course it is a needed feature. I also came across a real situation where it is useful. |
Yes, I can relate to usecases described here by others. I think this feature migh simplyfy development a lot.
Nice empathy there my friend. |
Directive to iterate over a FormArray:
Use
|
I had this problem a couple of times, too. Is there any update on this issue except the workarounds? |
There is no [formArray] directive but you can use [formGroup] and map it to a formArray let's say export class Component {
formArrayRef = new FormArray( [ new FormGroup( { name: new FormControl(null) } ) ] );
// operations with adding or removing data from the formArrayRef
// and let's suppose that the form array contains form groups inside
} <form [formGroup]="formArray">
<div *ngFor="let formGroupRef of formArrayRef.controls" [formGroup]="formGroupRef ">
<input formControlName="name" />
</div>
</form> even tho it's a bit counter intuitive to put a formArray into a [formGroup] it works 🔥 |
This works, I think remember in Angular 6 or Angular 7, but not in newer version |
inspired by #30264 (comment) stackblitz example working on Angular 16: |
Amazing!! It's looks like Angular guys solved!! (I'm pretty sure that not worked before, but it's possible I was wrong all this long time). Thanks @ezhupa99 |
Just to clarify: The behavior here has not changed. You were always able to iterate over the controls of a This feature request is about a directive that consumes
Passing a |
Wow, it feels quite ridiculous to see this obvious issue hanging around for 3.5 years already with no official attention from the Angular team 😕 |
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object. * `NgControlStatusGroup` directive will be applied to the `FormArrayDirective` * `NgForm` will still create a `FormGroup` Fixes angular#30264
🚀 feature request
Relevant Package
This feature request is for @angular/formsDescription
There should be a [formArray] directive to create a form. Currently, we can defined formArrayName only if has a parent [formGroup] directive.Describe alternatives you've considered
No work around to do this as of now. If we need a formArray, then a parent formGroup is needed.The text was updated successfully, but these errors were encountered: