PrimeNG - How to dynamically add and remove p-tabPanel in p-tabView component

I am working on a project where I need to use p-tabView. A new p-tabPanel should be created when a button is clicked in p-tabView.

How can I dynamically add new panels to p-tabView?

+4
source share
2 answers

I understood the way. I use ngFor to control # 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 the [selected] attribute when using * ngFor in p-tabPanel. You will get the following error:

TabPanel.html:2 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'none'. Current value: 'block'.
+4

. TabPanel.

tabs: TabPanel = [{header: 'tabbdfd', selected : false, disabled : false ,closable : true, closed : false}, {header: '3333', selected : false, disabled : false ,closable : true, closed : false}];

:

<p-tabView>  
     <p-tabPanel *ngFor="#tab of tabs" [header]="tab.header" >
            <CONTENT>   
    </p-tabPanel>
</p-tabView> 

, -:)

0

Source: https://habr.com/ru/post/1653986/


All Articles