I am creating nested components. Having multiple formGroups I want to bind them dynamically. For eg.
forGroup in a component is like
formGroup : {
controls:{
firstName: FormControl,
lastName: FormControl,
userName: FormControl,
Password: FormControl
}
}
HTML is something like & it is for multiple controls..
<div [formGroup]='formGroup'>
<div class="error-box">{{formGroup.controls.get('firstName').errors}}</div>
<div *ngIf="formControl.firstName?.visible" [ngClass]="{'has-error': formControl.firstName.error}">
<label>{{formGroup.controls.get('firstName').label}}</label>
<input type="text" formControlName="firstName" [maxlength]="formContrl.firstName?.maxLength">
<span class="error" *ngif="formControl.firstName.error"></span>
</div>
<div class="error-box">{{formGroup.controls.get('lastName').errors}}</div>
<div *ngIf="formControl.lastName?.visible" [ngClass]="{'has-error': formControl.lastName.error}">
<label>{{formGroup.controls.get('lastName').label}}</label>
<input type="text" formControlName="lastName" [maxlength]="formContrl.lastName?.maxLength">
<span class="error" *ngif="formControl.lastName.error"></span>
</div>
</div>
I want to bind the controls in common component.
I tried this.
<text-input [group]="formGroup.controls.firstName" [formControls]="formControl.firstName"></text-input>
So I am creating common HTML but when I try to bind this its giving me error on binding the directive formControlName="formControls.name //withwhat I am passing"