Repository navigation
Description
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>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
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
Activity
csisy-bt4w commentedon Mar 14, 2024
I'd like to add to this, I'm not sure however, if related or not. Some selectors do not work if the content itself is generated (e.g. with
@ifor@for). Consider the following example:By using this component, an element with a
routerLinkdirective is only projected if it is given as a content directly:However, if generated dynamically, then nothing is projected, nothing is shown:
Please note: if I use a component attribute name as a selector (e.g.
[app-custom]), then it works. I think this is because in this case, the html element itself contains an attribute with the same name.Edit:
Also, this is a regression, we updated our project to the latest (17.3.0) version, and it was working in version 17.1.0
Edit 2:
This seems to be a bug related to the new template pipeline. In the tsconfig if we added
"useTemplatePipeline": falsethen everything works as expected.pkozlowski-opensource commentedon Mar 14, 2024
@csisy-btw could you please open a separate issue for your use-case, ideally with a minimal reproduction scenario in a stackblitz? Otherwise we might miss this one. Thnx!
pkozlowski-opensource commentedon Mar 15, 2024
PR: #54879
fix(core): correctly project single-root content inside control flow
fix(core): correctly project single-root content inside control flow (#…
angular-automatic-lock-bot commentedon Apr 22, 2024
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.