2

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.

HiddenMarkow
  • 603
  • 1
  • 7
  • 19
  • @yurzui I followed another answer from you https://stackoverflow.com/questions/46976570/how-to-render-multiple-ng-content-inside-an-ngfor-loop-using-angular-4 to get the above situation – HiddenMarkow Jul 22 '20 at 12:55
  • Can you please reproduce this issue in stackblitz? – yurzui Jul 22 '20 at 13:20

0 Answers0