Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component Panel: Adding control flow inside ng-template for header is not working anymore #16971

Closed
kribot opened this issue Dec 6, 2024 · 4 comments
Assignees
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Milestone

Comments

@kribot
Copy link

kribot commented Dec 6, 2024

Describe the bug

When adding control flow operator like @if in ng-template in Panel it breaks the template and the content is not rendered.

Environment

18.0.3

Reproducer

https://stackblitz.com/edit/github-akrybn?file=src%2Fapp%2Fapp.component.html

Angular version

18.0.3

PrimeNG version

18.0.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

21.6.2

Browser(s)

No response

Steps to reproduce the behavior

Create a panel with a template
<p-panel [toggleable]="true">

Prime
@if (1 === 1) {
NG
}

Expected behavior

Result should display Prime NG, instead it removes everything

@kribot kribot added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 6, 2024
@kribot kribot changed the title Panel: Adding @if inside ng-template for header is not working anymore Component Panel: Adding control flow inside ng-template for header is not working anymore Dec 6, 2024
@0x426
Copy link

0x426 commented Dec 7, 2024

Having the same error with some other components, check this out:

@mertsincan mertsincan added Status: Pending Review Issue or pull request is being reviewed by Core Team and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 7, 2024
@mertsincan mertsincan added this to the 18.0.1 milestone Dec 7, 2024
@github-project-automation github-project-automation bot moved this to Review in PrimeNG Dec 7, 2024
@can-oezkan
Copy link
Contributor

As a workaround, using <ng-template #header /> instead of <ng-template pTemplate="header" /> seems to work.

Regarding the cause of this bug, I suspect that when using @ContentChild('header') headerTemplate, Angular reassigns the value if it encounters a control flow block like @defer, @if, @for, or @switch within the headerTemplate.

Due to this reassignment by Angular, we lose the reference to the pTemplate, which is initialized in basecomponent.ts by manually setting the headerTemplate variable:

ngAfterContentInit() {
this.templates?.forEach((item) => {
const type = item.getType();
const template = `${type}Template`;
if (this.hasOwnProperty(template)) {
this[template] = item.template;
}
if (this.hasOwnProperty(`_${template}`)) {
this[`_${template}`] = item.template;
}
this[type] = item.template;
});
}

This means the scope of this bug could extend to other components that use the @ContentChild decorator.

@vanackej-onemw
Copy link

Hi.
Just to add a precision : the workround (using # syntax) works partially, but fails with nested components (like panel in panel), as the outer panel uses the customized header of the first nested panel if the outer panel as no header template defined.

@mehmetcetin01140
Copy link
Contributor

Fixed in 4f766b2

@github-project-automation github-project-automation bot moved this from Review to Done in PrimeNG Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Projects
Status: Done
Development

No branches or pull requests

7 participants