В моем приложении есть панель вкладок. Я добавил кнопку, которая позволяет добавить новую вкладку. Вкладка добавлена правильно, но моя проблема в том, что я не могу добавить в tabPanel нужную форму.
Изначально есть несколько вкладок с их данными. Я хочу добавить новую вкладку с пустой формой.
<ng-template #risposteTemplate let-index="index">
<form [formGroup]="risposteFormGroup">
<p-tabView #risposteTabView *ngIf="domandeItems[index].risposte && domandeItems[index].risposte.length > 0">
<p-tabPanel *ngFor="let risposta of domandeItems[index].risposte; let i = index;"
header="{{'questionario.riposte_possibili_header'|translate}}: {{risposta.order}}">
<div class="row w-100 mb-1">
<!-- testo risposta -->
<div class="col-xs-5 col-sm-5 col-md-5 col-lg-5 form-group">
<label
class="font-weight-bold">{{'questionario_risposte_rangeValoreA' | translate}}</label>
<label class="font-weight-bold">{{'questionario_testo' | translate}}</label>
<textarea formControlName="testo-{{i}}" class="questionario-input-border form-control"
type="text" rows="2" cols="90"></textarea>
</div>
<div class="col-xs-5 col-sm-5 col-md-5 col-lg-5 form-group">
<label class="font-weight-bold">{{'questionario_help' | translate}}</label>
<textarea formControlName="help-{{i}}" class="questionario-input-border form-control"
type="text" rows="2" cols="90"></textarea>
</div>
</div>
</p-tabPanel>
</p-tabView>
</form>
</ng-template>
У меня есть функция
@ViewChild('risposteTabView', { static: false }) risposteTabView: TabView;
@ViewChild('risposteTemplate', { static: false }) risposteTemplate: TemplateRef<any>;
nuovaRisposta(event, index) {
const tab: TabPanel = new TabPanel(this.viewContainerRef);
tab.header = this.translate.instant('questionario.riposte_possibili_header');
this.risposteFormGroup.addControl('testo-' + this.lastRisposteIndex, new FormControl(null, Validators.required));
this.risposteFormGroup.addControl('help-' + this.lastRisposteIndex, new FormControl(null));
this.risposteTabView.tabs.push(tab);
// disabilito il selected true dagli altri tab
for(let n = 0; n < this.risposteTabView.tabs.length; n++) {
this.risposteTabView.tabs[n].selected = false;
}
this.risposteTemplate.createEmbeddedView('test');
tab.selected = true;
}
, сейчас она правильно добавляет новую вкладку. Я хочу также ввести в форму данные. Есть ли способ?