primeng icon indicating copy to clipboard operation
primeng copied to clipboard

tabView with *ngIf malfunction

Open sforest1975 opened this issue 6 years ago • 7 comments

[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

tabView in 10.0.0-rc1 malfunction if using *ngIf.

app.component.html

<p-tabView>
  <p-tabPanel header="Header 0">
    Content 0
  </p-tabPanel>
  <p-tabPanel header="Header 1" *ngIf="mode == 1">
    Content 1
  </p-tabPanel>
  <p-tabPanel header="Header 2" *ngIf="mode == 2">
    Content 2
  </p-tabPanel>
</p-tabView>

<p-button label="Click" (click)="onClick()"></p-button>

app.component.ts

  mode = 0;

  onClick() {
    this.mode++;
  }

In this case, firstly 'Header 0' only displays. (mode = 0)

push, button, mode become 1. but, html nothing change. this should be display 'Header 0' and 'Header 1'. (If click 'Header 0', 'Header 1' display). angular 9 work properly.

Please fix this problem, and/or please let me know how to show 'Header 1' manually without user click.

sforest1975 avatar Aug 06 '20 02:08 sforest1975

I experience that no dynamic changes from code is reflected, e.g. adding or removing items from a tabs array used in and ng-for statement is not applied either. Referencing the tabview component from code and calling this.tabView.cd.markForCheck() makes the changes get applied, even solves the case above.

WillooWisp avatar Sep 18 '20 18:09 WillooWisp

I can confirm, using ngFor for dynamic tabs as stated in the documentation does not reflect changes on bound property. Using a ngIf on the p-tabView itself solves the issue for me. Stackblitz

valleschwarz avatar Sep 29 '20 11:09 valleschwarz

I think i have a similar issue: https://forum.primefaces.org/viewtopic.php?f=35&p=185930#p185930

But this.tabView.cd.markForCheck() does not work for me. @WillooWisp Where do you call this.tabView.cd.markForCheck()? In ngAfterViewInit it does not work

OPunktSchmidt avatar Oct 29 '20 13:10 OPunktSchmidt

Okay, found a solution for me. This works for me. But of course it is dirty as hell. For me it was important to call markForCheck not immediately.

    ngAfterViewInit() {
        setTimeout(() => {
            this.loginTabView.cd.markForCheck();
        }, 100);
    }

OPunktSchmidt avatar Oct 29 '20 13:10 OPunktSchmidt

similar issue hapens for me if you want to display tabs conditionaly with ngIf. If every tabPanel has ngif condition you receive

Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'undefined'. Current value: 'true'

if you have at least 1 tabpanel without ngIf it works flawlessly

matusko89 avatar Dec 21 '21 20:12 matusko89

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you reopen the issue so we can include it in our roadmap? Please don't forget to add your feedback as a comment after reopening the issue. These will be taken into account by us and will contribute to the development of this feature. Thanks a lot for your understanding!

Best Regards,

mertsincan avatar Nov 09 '22 19:11 mertsincan

Still happens with lazy-loaded tabs in primeNG 14.2.2

MaksymShchukin avatar Nov 22 '22 13:11 MaksymShchukin