I'm on a project where I need to use a p-tabView. A new p-tabPanel is to be created when clicking on a button in the p-tabView.
How can I dynamically add new panels to a p-tabView?
I figured out a way. I am using ngFor to control the # of tabPanel.
My component.ts code will manipulate myModel.leads. Thus, the number of tabPanel will change accordingly.
<!--Lead-->
<p-tabView >
<p-tabPanel [selected]="i==0" *ngFor="let lead of procedureDetail.leads; let i = index" header="lead {{i+1}}" >
<div id="{{lead.id}}" class="my_dynamica_lead_tabPanel"> <!-- I can add content to this div with tabView.onChange() api -->
{{lead.id}} - {{i}}
</div>
<div class="row">
<div class="col-md-3">
Date:
</div>
<div class="col-md-9">
<p-calendar [style]="{'width':'180px'}" [monthNavigator]="true" [yearNavigator]="true" yearRange="1900:2020" name="lead.{{i}}.date" [(ngModel)]="lead.date" [showIcon]="true" ></p-calendar>
</div>
</div>
</p-tabPanel>
</p-tabView>
Note - If you forget to include [selected] attribute while using *ngFor in p-tabPanel. You will get following error
TabPanel.html:2 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'none'. Current value: 'block'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With