I have form array, I am having hard time solving this.
this is my current code
.ts
ngOnInit() {
this.item = this.fb.group({
codeId: ['', Validators.pattern(/^\d+$/)],
name: ['', [Validators.required, Validators.minLength(3)]],
stepTextarea: ['', []],
steps: [this.fb.array([]), []]
});
}
addProcedure (e): void {
e.preventDefault();
const control = <FormGroup>this.item;
const steps = <FormArray>this.item.controls['steps'];
steps.push(control.get('stepTextarea').value);
control.get('stepTextarea').setValue("", {onlySelf: true})
}
onSubmit({value, valid}: {value: Item, valid: boolean}): void {
const control = <FormGroup>this.item;
console.log(value);
}
.html
<ol ngFor [ngForOf]="item.get('steps').controls">
<span [formGroupName]="i">{{i}}</span>
</ol>
I am having hard time how to populate and also push. I cant find any tutorial.
EDIT
I want something like this on submit
{
codeId: 123,
name: "wew",
stepTextarea: "",
steps: ['asdjlkas','12312','12321']
}