将索引从 ng-container 传递到 ng-template
Passing index from ng-container to ng-template
我想将索引从 *ngFor 传递到 ng-container
到 ng-template
。
但是好像不行
<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>
怎么了??好像没有通过索引
Cannot find control with name: 'order-'
进行 2 处更改:
context: {index: i}
let-index="index"
这样试试:
<ng-container *ngTemplateOutlet="titleTemplate; context: {index: i}"></ng-container>
<ng-template #titleTemplate let-index="index">
</ng-template>
我想将索引从 *ngFor 传递到 ng-container
到 ng-template
。
但是好像不行
<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>
怎么了??好像没有通过索引
Cannot find control with name: 'order-'
进行 2 处更改:
context: {index: i}
let-index="index"
这样试试:
<ng-container *ngTemplateOutlet="titleTemplate; context: {index: i}"></ng-container>
<ng-template #titleTemplate let-index="index">
</ng-template>