I have something like this in parent component say 'parent-component' - add/remove value functionality. The consuming component can provide <input> , <textarea>
etc
<ng-container *ngFor="let val of values; let $index = index;">
<ng-container *ngTemplateOutlet="keyInputTmpl, context: { item: val, index: $index }"></ng-container>
<!-- button to add /remove elements from 'values' -->
</ng-container>'
parent-component.ts:
@ContentChild('keyInput', {static: true}) keyInputTmpl: TemplateRef<any>;
Also, I have something like this in 'child-component'
<parent-component [(values)]="someValues"
[readOnly]="readOnly">
<ng-template #keyInput let-item="item" let-index="index">
<input type="text"
size="25"
[name]="'name_'+index"
[(ngModel)]="item && item.name">
</ng-template>
</parent-component>
`
The problem is that the value I enter in <input>
of child-component.ts
is not available in the parent-component
. I think the let-item
is not working the way I expect it.
If using templates is not the right thing how can this problem be solved using other angular constructs? (I also tried using ng-content
but that does not support multiple elements like in the case of *ngFor).
Tried researching for a long time and could not find a solution.