-
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
docs: add sample usage of the FormArray API for reactive forms #54138
base: main
Are you sure you want to change the base?
Conversation
@maequise Looks like your commit message is causing the lint to fail. It's very close though. Run |
@dylhunn Can you review the content here? |
Deployed adev-preview for 9a09d02 to: https://ng-dev-previews-fw--pr-angular-angular-54138-adev-prev-6sk3qzg2.web.app Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt. |
4bdda83
to
19ae375
Compare
selector: 'my-form-comp', | ||
standalone: true, | ||
imports: [ReactiveFormsModule] | ||
//component declaration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is not revelant, I certainly forgot to remove it. If need I can remove it and make a new push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, remove anything that is not relevant.
@@ -392,6 +392,192 @@ Initially, the form contains one `Alias` field. To add another field, click the | |||
|
|||
</docs-workflow> | |||
|
|||
## A more concrete usage of FormArray | |||
|
|||
In a more concrete sample, we can imagine the following use case. You are application needs a basic form, with known information, but the user has the ability to add more or less sub-form. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a more concrete sample, we can imagine the following use case. You are application needs a basic form, with known information, but the user has the ability to add more or less sub-form. | |
In a more concrete sample, we can imagine the following use case. Your application needs a basic form, with known information, but the user has the ability to add more or less sub-form. |
|
||
And in the template we have our principal form displayed and mapped, and a `@for` loop used to iterate over the `FormArray`. | ||
|
||
Tip: If you watch the HTML template, you will notice that the access to the `FormArray` is not from the `FormGroup` directly with the **get()** method. We will define a getter method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip: If you watch the HTML template, you will notice that the access to the `FormArray` is not from the `FormGroup` directly with the **get()** method. We will define a getter method. | |
Tip: If you watch the HTML template, you will notice that the access to the `FormArray` is not from the `FormGroup` but directly using the **get()** method. We will define a getter method. |
} | ||
} | ||
``` | ||
With this method, when the user click on the button, it is adding a new `FormGroup` in the `FormArray`. When adding a new entry, the template will be updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this method, when the user click on the button, it is adding a new `FormGroup` in the `FormArray`. When adding a new entry, the template will be updated. | |
With this method, when the user clicks on the button, it is adding a new `FormGroup` in the `FormArray`. When adding a new entry, the template will be updated. |
|
||
<docs-step title="Add possibility to remove an entry"> | ||
|
||
We can add entries to the `FormArray` but we should be able to remove a specific entry. The `FormArray` has the **removeAt()** method that permits to delete a specific index of the `FormArray`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add entries to the `FormArray` but we should be able to remove a specific entry. The `FormArray` has the **removeAt()** method that permits to delete a specific index of the `FormArray`. | |
We can now add entries to the `FormArray` but we should also be able to remove a specific entry. The `FormArray` has the **removeAt()** method that permits to delete a specific index of the `FormArray`. |
39b6365
to
89787a0
Compare
@sonukapoor thank you for the review, I made the corrections (the last forced "push" was because I missed one edit) |
I really appreciate this work but this should really be a tutorial or code example, not necessarily an additional guide. I would also add here that we should consider revamping this guide and converting it to an issue that we should track and keep track of this work. @twerske can you chime in on this? |
I was thinking earlier in the afternoon adding a tutorial on the suject. |
I agree. This should be a tutorial not a guide since it's a walk through of a code example. |
89787a0
to
9a09d02
Compare
As suggested, I made a tutorial for this part and removed the guide part. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Missing a more concrete sample on how to use the FormArray API
Issue Number: #53705
What is the new behavior?
Include a more concrete sample of how to use the FormArray API on the site into the guide of reactive forms
Does this PR introduce a breaking change?
Other information