I'm building a form with nested inputs. I've found an example of what I need and I'm trying to implement it in my app. What I don't get is how to conditionally display input type - according to the form's meta data.
Here is the markup:
<form class="tree" [formGroup]="testForm" (ngSubmit)="onSubmit()">
<ng-template #recursiveList let-controls let-prefix="prefix" >
<ng-container *ngFor="let item of controls; let i = index">
<div class="tree-item" [formGroup]="testForm.get(prefix + i)">
<input type="text" formControlName="type">
</div>
<div class="sub-tree" *ngIf="item.get('element')?.controls?.length">
<ng-container
*ngTemplateOutlet="recursiveList; context:{ $implicit: item.get('element').controls, prefix: prefix + i + '.element.' }"></ng-container>
</div>
</ng-container>
</ng-template>
<ng-container
*ngTemplateOutlet="recursiveList; context:{ $implicit: testForm.get('element').controls, prefix: 'element.' }"></ng-container>
</form>
Here is the meta data:
export const data: TreeItem = {
'element': [{
'name':'age',
'label':'Age',
'fieldType':'select',
'type': '',
'element': [
{ 'name':'dateOfBirth',
'label':'Date Of Birth',
'fieldType':'date',
'type': '',
'element': []}
]
}],
};
I wonder how can I do something like:
<input type="date" formControlName="item.name" *ngIf="item.inputType === 'date'>
<input type="text" formControlName="item.name" *ngIf="item.inputType === 'input'>