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

<ng-template> with [ngIf] does not render SVG content #41308

Closed
baarney opened this issue Mar 22, 2021 · 2 comments
Closed

<ng-template> with [ngIf] does not render SVG content #41308

baarney opened this issue Mar 22, 2021 · 2 comments
Assignees
Labels
area: core Issues related to the framework runtime cross-cutting: SVG P4 A relatively minor issue that is not relevant to core functions state: has PR
Milestone

Comments

@baarney
Copy link

baarney commented Mar 22, 2021

🐞 bug report

Affected Package

Probably @angular/core ?

Is this a regression?

Don't know

Description

When using an <ng-template> in the non-asterisk longhand form to render SVG fragments, neither the main template nor the else template are rendered:

    // component
    test=true;
  
    // template
    <svg width="200" height="80">
      <text x="0" y="20">SVG Test</text>
      <ng-template [ngIf]="test" [ngIfElse]="svgElse">
        <text x="0" y="40">SVG Test True</text>
      </ng-template>
      <ng-template #svgElse>
        <text x="0" y="40">SVG Test False</text>
      </ng-template>
    </svg>

    // rendered output
    <svg _ngcontent-gar-c204="" width="200" height="80">
      <text _ngcontent-gar-c204="" x="0" y="20">SVG Test</text>
      <!--container-->
      <!--container-->
    </svg>

Note that using <ng-container> with the structural *ngIf form does work:

    <svg width="200" height="80">
      <text x="0" y="20">SVG Test</text>
      <ng-container *ngIf="test else svg2Else">
        <text x="0" y="40">SVG Test True</text>
      </ng-container>
      <ng-template #svg2Else>
        <text x="0" y="40">SVG Test False</text>
      </ng-template>
    </svg>

Given other issues I've had with svg, I've tried both with and without svg: namespace prefixes on the child svg elements. Seems to exhibit the same behaviour in both cases.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-ivy-kpeerk

🌍 Your Environment

Angular Version:


Angular CLI: 11.2.2
Node: 14.15.5
OS: linux x64

Angular: 11.2.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1100.7
@angular-devkit/build-angular   0.1102.2
@angular-devkit/core            11.2.2
@angular-devkit/schematics      11.2.2
@angular/cdk                    11.2.2
@angular/cli                    11.2.2
@schematics/angular             11.2.2
@schematics/update              0.1102.2
rxjs                            6.6.6
typescript                      4.1.5
 

Anything else relevant?

@AndrewKushnir AndrewKushnir added area: core Issues related to the framework runtime cross-cutting: SVG labels Mar 22, 2021
@ngbot ngbot bot modified the milestone: needsTriage Mar 22, 2021
@jelbourn
Copy link
Member

Expanded StackBlitz: https://stackblitz.com/edit/angular-ivy-bwuaql?file=src%2Fapp%2Fapp.component.ts

Confirmed that this looks looks to be a real bug

@jelbourn jelbourn added the P4 A relatively minor issue that is not relevant to core functions label Mar 24, 2021
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Mar 24, 2021
@crisbeto crisbeto self-assigned this Apr 17, 2021
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 17, 2021
…ide alternate namespaces

We have a check that determines whether to generate property binding instructions for an `ng-template`. The check looks at whether the tag name is exactly `ng-template`, but the problem is that if the tag is placed in a non-HTML namespace (e.g. `svg`), the tag name will actually be `:namespace:ng-template` and the check will fail.

These changes resolve the issue by looking at the tag name without the namespace.

Fixes angular#41308.
AndrewKushnir pushed a commit that referenced this issue Apr 20, 2021
…ide alternate namespaces (#41669)

We have a check that determines whether to generate property binding instructions for an `ng-template`. The check looks at whether the tag name is exactly `ng-template`, but the problem is that if the tag is placed in a non-HTML namespace (e.g. `svg`), the tag name will actually be `:namespace:ng-template` and the check will fail.

These changes resolve the issue by looking at the tag name without the namespace.

Fixes #41308.

PR Close #41669
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime cross-cutting: SVG P4 A relatively minor issue that is not relevant to core functions state: has PR
Projects
None yet
4 participants