Skip to content

Conditionals and content projection #54840

@pkozlowski-opensource

Description

@pkozlowski-opensource

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

core

Is this a regression?

No

Description

There is a surprising interaction between our static (creation time) content projection system and the new control flow (although this is not specific to the new control flow - the same can be observed with ngIf).

To illustrate the surprising scenario let's consider a component with content projection with a selector (<ng-content select="some-content">) and content to project wrapped in the control flow @if statement with the else branch:

<with-content>
      @if(false) {          
        <some-content />
      } @else {
        I'm not the content queried for, don't project me! 
      }
</with-content>

https://stackblitz.com/edit/stackblitz-starters-57dynz?file=src%2Fmain.ts

As surprising as it may be, the I'm not the content queried for, don't project me! text node will be taken as content to project (!). This is consistent with the existing implementation which will project the whole @if container and container capturing the some-content as a tag name of a root node.

While we can't fix all issues with the content projection, we could remedy this one by

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-57dynz?file=src%2Fmain.ts

Please provide the exception or error you saw

No response

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

No response

Anything else?

No response

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions