FormArray insert and setControl insert items on wrong index
See original GitHub issueI’m submitting a … (check one with “x”)
[X] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior Documentation for insert says that item is inserted on the given index.
Insert a new AbstractControl at the given index in the array.
However if the controls
collection is empty the item is always inserted on first position. The issue is due to inappropriate usage of splice here.
Expected behavior To always insert the item at the given index.
Minimal reproduction of the problem with instructions http://plnkr.co/edit/zS5RlQhRVWpviWWK99JO?p=preview
What is the motivation / use case for changing the behavior? We need to add FormGroups dynamically in FormArray based on relative index and later retrieve it back from that index.
- Angular version: 2.2.3
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
how to use insert function in FormArray? - Stack Overflow
first you need to push(new FormControl) blank formControl and then a sing value using setControl(index object).
Read more >FormArray - Angular
Index in the array to insert the control. If index is negative, wraps around from the back. If index is greatly negative (less...
Read more >Angular Reactive Forms: The Ultimate Guide to FormArray
It inserts a new AbstractControl at the given index in the controls ... Since the FormArray now holds FormGroup objects, we need to...
Read more >Very simple Example to understand Angular FormArray and ...
FormArray is a very useful concept when you wish to add a FormGroup or another FormArray ... setControl('items',this.fb.array(transformedItems));
Read more >Angular FormGroup addControl() and removeControl()
The form control can be FormGroup , FormControl and FormArray . Find the methods of FormGroup used to add, update or remove controls....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@kara Please re-open this issue!
insert
documentation claims that items is inserted at position. I’m not willing to usesetControl
.setControl
will not work if there isn’t item at the given position, whileinsert
should work. What is the purpose of the index parameter then? It is pointless unless the array is already populated.This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.