Need assistance with handling a collection in an Angular component:
collection: collectionAbs[];
export interface collectionAbs{
name: string;
prop: string;
secondProp: number;
}
Initialization:
this.collection.forEach((item ,index) => {
formGroup.addControl(index.toString() + "-prop", new FormControl('', [Validators.required])),
formGroup.addControl(index.toString() + "-secondProp", new FormControl('', [Validators.required]))
});
The object is set up and now I need to update properties in the form. Here is what I have:
<div *ngFor="let item of collection; let i = index" >
<input type="text" name="collection[{{i}}].prop">
<input type="number" name="collection[{{i}}].secondProp">
</div>
I'm unsure how to assign these values back to my collection objects. Any better solutions to handle this issue?
@Edit
FormGroup:
var formGroup: FormGroup;
formGroup = new FormBuilder().group({
anotherFormInputOne: new FormControl(null, [Validators.required]),
anotherFormInputTwo: new FormControl(null, [Validators.required])
});
Thank you!