I want to update formArrayafter the user adds a value to the empty created control.
Currently, when the user selects to add a new element i, created on formArraywith empty values.
buildItem(item?: any, key?: any): FormGroup {
let itemName: string;
let keyValue: string;
if (item === undefined) {
itemName = ''; key = '' }
else {
itemName = item.name; keyValue = key
};
return this.formBuilder.group({
item: [itemName || '', Validators.required],
properties: { item, key: key } || {} });
}
This is great for initially creating and updating already added items. The problem is with new items that are added with empty values. When I add a new item, I need to add a return key from firebase toproperties.key
In the save method of this new item, I added patchValue
this.items.patchValue([{
// item being returned from firebase promise
item: item.name,
properties: { item: item.name, key: item.$key' }
}]);
patchValue . , firebase, , BuildItem(), patchValue
angular formArray,
, , , . REF
, .. , ? , , , . removeAt(idx)
, -
this.form.patchValue.atIndex(this.idx,[{
item: item.name,
properties: { item: item.name, key: item.$key' }
}];
, .. , . , formArray, , , .
, formArray
this.items.push(this.buildItem(...));
this.items.removeAt(this.idx);
, - .