-
Notifications
You must be signed in to change notification settings - Fork 33
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
NgxFormWithArrayControls access formControlName ? #197
Comments
is there a question here? |
Yes |
The reason you have to create a new component is because ngx-sub-form is not aware of your nested data. The good thing about nested forms (and behind the scenes ControlValueAccessor) is that it lets us deal with only the first layer of an object and we can either use that as it is (an object) or delegate the breakdown of this object to another sub form. Otherwise, your idea of sub forms would be broken and we'd have to deal with loads of data in 1 component. So from there, you have 2 options:
Please read the doc for the second solution first. If that doesn't make sense I'm happy to help if you provide first a minimal reproduction on stackblitz |
I need to edit the component in the table to access it with |
Can you explain a bit more in details what I am supposed to look at in your stackblitz please? For example, explain what the current state is, what is not working and/or what you'd like to do |
@elvispdosreis you cannot do <tbody>
<tr *ngFor="let compartment of formGroupControls.compartments.controls; let i = index;">
<td>{{i}}</td>
<td>{{compartment.value.deck}}</td>
<td><input [formControlName]="compartment.size"></td> <--------------- this Compartment is a By calling case "compartments":
return new FormControl(value, [Validators.required]); So when you do To allow the modification of the value property you need to create a sub form and pass this whole FormControl then allow only to edit the I've made you an example here: Note: While the value is binded correctly initially, note that if you update the value from the table, it won't update the value in the form above :/ But I believe that you're not hitting a limitation from ngx-sub-form but rather angular itself: angular/angular#13792 I've also commented on this issue with a minimal repro: angular/angular#13792 (comment) I believe this is the same limitation in this case. I'm going to close this as everything has been answered, feel free to reopen if it doesn't :) |
I have a component created with NgxFormWithArrayControls and I need in ngfor to access the form control name
the examples that I have seen and transform the input into another form component to do this, but it is so simple that there is no need to transform it into a component
The text was updated successfully, but these errors were encountered: