primeng icon indicating copy to clipboard operation
primeng copied to clipboard

ngFor/ngIf not working for generate a list of tabPanel

Open ghost opened this issue 9 years ago • 13 comments

I'm submitting a ... (check one with "x")

[x ] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

My problem is simple. I have the following code, to generate a liste of tabPanel with a list of objets.

@Input()
perimeters: BeneficiaryPerimeter[];

<div class="panel-body" *ngIf="perimeters?.length > 0">
<p-tabView orientation="left">
   <p-tabPanel [header]="perimeter.name" *ngFor="let perimeter of perimeters">
           {{perimeter}}
   </p-tabPanel>
</p-tabView>
</div>

It generates the following error: EXCEPTION: Error in ./TabPanel class TabPanel - inline template:1:56 caused by: Expression has changed after it was checked. Previous value: 'none'. Current value: 'block'.

This code is working:

<p-tabView orientation="left">
    <p-tabPanel [header]="perimeters[0].name">
             {{perimeters[0]}}
      </p-tabPanel>
</p-tabView>

This code is not working:

<p-tabView orientation="left">
     <p-tabPanel [header]="perimeters[0].name" *ngIf="perimeters[0]">
             {{perimeters[0]}}
       </p-tabPanel>
</p-tabView>

Please tell us about your environment:

  • Angular version: 2.4.6
  • PrimeNG version: 2.0.0-rc3
  • Browser: [Chrome 56]

ghost avatar Feb 06 '17 10:02 ghost

I tried simulate but here worked. Can you make a plunkr?

Just to know:

The error look about our NgIf expression - the first time it runs, [style.display] is 'none', then ngAfterContentInit() runs and changes the value to something other than 'block'.

But I can not simulate the problem.

upmauro avatar Feb 15 '17 14:02 upmauro

I have found the "problem"

https://plnkr.co/edit/DEJXu5rQhtfgvvzoJcM1

I have two level of tabView:

<p-tabView> <p-tabPanel header="Tab1"> <p-tabView orientation="left"> <p-tabPanel header="{{data.var1}}" *ngFor="let data of datas"> Content 1 </p-tabPanel> </p-tabView> </p-tabPanel> </p-tabView>

With only one level, it's working (like you had tested), but in my case, with a second 'level', I can reproduce the problem.

Note: If i had [selection]=true to the second tabPanel, it's working (strangely).

ghost avatar Feb 15 '17 21:02 ghost

I can confirm that this bug exists but for me it looks like *ngFor is the cause. For example:

<p-tabView>
<p-tabPanel *ngFor="let tab of tabs" header="someheader"></p-tabPanel>
</p-tabView>

is invalid while adding at least one static tab:

<p-tabView>
<p-tabPanel header="dummy"></p-tabPanel>
<p-tabPanel *ngFor="let tab of tabs" header="someheader"></p-tabPanel>
</p-tabView>

makes it work as expected.

m-tomczyk avatar Apr 11 '17 13:04 m-tomczyk

see this post on forum: https://forum.primefaces.org/viewtopic.php?p=153436#p153436 its working!

Arsenal83 avatar May 17 '17 05:05 Arsenal83

This should be fixed in recent PrimeNG release, please try with it and if the issue persists drop a comment with along with a test case based on plunkr below and we'll review again.

http://plnkr.co/edit/Wj39h1?p=preview

cagataycivici avatar Jun 19 '17 13:06 cagataycivici

This is still a problem with *ngIf

Here's a plunkr that reproduces the problem:

http://plnkr.co/edit/BLg0fYTAe62CyKtUlaFS?p=preview

scottieslg avatar Jul 07 '17 18:07 scottieslg

Yes, still a problem latest version 4.1.3

kuriel-dev avatar Aug 15 '17 20:08 kuriel-dev

the @m-tomczyk 's solution works, but only if you add the tab at the first place, in my case i need the static tab at the last one, and error persists

kuriel-dev avatar Aug 15 '17 20:08 kuriel-dev

the @Arsenal83 quoted solution, works!!

kuriel-dev avatar Aug 15 '17 20:08 kuriel-dev

@ikuriel that solution only works if you always intend to load the component with the first tab selected. This is still broken.

slugworth avatar Oct 13 '17 15:10 slugworth

i found the solution to sovle this error. you can add code like below. <p-tabPanel *ngFor="let x of xxx; let i = index ;" [selected]="i == 0? true:false" [header]=" headerxxxx">

ghost avatar Nov 01 '17 03:11 ghost

@jaxiell saved my day!! Works for me!

lxyangfan avatar Nov 06 '17 06:11 lxyangfan

@jaxiell this solution fixes the error but also breaks lazy loading, now all tabs will be loaded even though I have wrapping up the content, I think this is still a bug.

luigiw avatar Feb 09 '18 17:02 luigiw