Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Multiple usage of ng-content inside if and else block not working #61282

Copy link
Copy link
Closed as duplicate of#7795
@sheikalthaf

Description

@sheikalthaf
Issue body actions

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

Yes

Description

If I put the ng-content in both If and else then it is only considering the else one and failed to render inside if block.

import { ChangeDetectionStrategy, Component, input } from '@angular/core';

@Component({
  selector: 'app-test',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    @if (mode() === 'selection') {
      <div>Selection: <ng-content /></div>
    } @else {
      <div>Toggle: <ng-content /></div>
    }
  `,
  host: {
    class: 'block border border-red-500',
  },
})
export class TestMode {
  readonly mode = input<'selection' | 'toggle'>('selection');
}

and usage in App.ts file

import { Component } from '@angular/core';
import { TestMode } from './test.component';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [TestMode],
  template: `
    <app-test mode="selection">
      <p>Hello S</p>
    </app-test>

    <app-test mode="toggle">
      <p>Hello T</p>
    </app-test>
  `,
  host: {
    class: 'block h-screen',
  },
})
export class AppComponent {}

Add it rendered as

Image

As you can see that it is missing the Hello S

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 19.2.9
Node: 20.18.0
Package Manager: pnpm 9.12.3
OS: darwin arm64

Angular: 19.2.8
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1902.9
@angular-devkit/build-angular   19.2.9
@angular-devkit/core            19.2.9
@angular-devkit/schematics      19.2.9
@angular/cli                    19.2.9
@schematics/angular             19.2.9
rxjs                            7.8.2
typescript                      5.7.3
zone.js                         0.15.0

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.