Here is the stackblitz for the code below. I am making a fairly complex deeply nested Angular form using FormArrays, and child components. For the most part, everything is w
Stackblitz demo
Let's replace groupInstance
for showConjunctor
just to make it more obvious about what it's there for.
You can do this in you app.component.hml
:
<app-group-control
#templateRef
(remove)="_delete(i)"
[formControlName]="i"
[formLabel]="'Group '+ (i + 1) + ':'"
[showConjunctor]="!((i + 1) % 2)">
</app-group-control>
I'm considering that i
, in the above snippet, is the index of the current loop in *ngFor
(like in the Stackblitz demo).
Also, remove this part from the app.component.html
:
<div *ngIf="i > 0">
<div [formGroupName]="i">
<input type="text" formControlName="conjunctor">
</div>
</div>
[UPDATE]: Per your comments, if you want to have the conjunctor in all
of the nested Groups, you can set the @Input() showConjuntor
to true inside the GroupControlComponent
(Stackblitz demo):
<ng-container formArrayName="groups">
<app-group-control *ngFor="let s of _groupsFormArray?.controls; index as i"
(remove)="_deleteGroupFromArray(i)"
[formControlName]="i"
[formLabel]="'Nested Group '+ (i + 1) + ':'"
[showConjunctor]="true">
</app-group-control>
</ng-container>