Reputation: 321
I wanna pass the index from an *ngFor to and ng-container
to ng-template
.
But it seems not working
<p-accordionTab *ngFor="let title of titleItems; let i = index;" class="mb-2" [selected]="true">
<p-header>
{{title}}
<span *ngIf="title.help" tooltip="{{title.help}}">
<i class="fa fa-question-circle"></i>
</span>
</p-header>
<ng-container *ngTemplateOutlet="titleTemplate; context: {$implicit: { index: i}}"></ng-container>
</p-accordionTab>
</p-accordion>
<ng-template #titleTemplate let-index>
<form [formGroup]="domandeFormGroup" class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-left">
<div>
<input formControlName="order-{{index}}"
class="title-input-border form-control" type="text">
</div>
</form>
</ng-template>
What is wrong?? It's seems that not passing the index
Cannot find control with name: 'order-'
Upvotes: 4
Views: 4847
Reputation: 22213
Make 2 changes:
context: {index: i}
let-index="index"
Try like this:
<ng-container *ngTemplateOutlet="titleTemplate; context: {index: i}"></ng-container>
<ng-template #titleTemplate let-index="index">
</ng-template>
Upvotes: 7