Skip to content

Control flow migration wrongly removes ng-template in a specific scenario #64741

@lukasmatta

Description

@lukasmatta

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

core

Is this a regression?

No

Description

The definition of the ng-template is wrongly removed after running ng generate @angular/core:control-flow in a specific scenario.

Before:

<div *ngIf="sampleVar else sampleTemplate">
  <ng-container *ngTemplateOutlet="sampleTemplate; context: {
                  value: 'sampleVar is true'
  }">
  </ng-container>
</div>

<ng-template #sampleTemplate let-value="value">
  <h1>{{ value ?? "sampleVar is false" }}</h1>
</ng-template>

After (see the definition of sampleTemplate has been removed even though it is still being used):

@if (sampleVar) {
  <div>
  <ng-container *ngTemplateOutlet="sampleTemplate; context: {
                  value: 'sampleVar is true'
  }">
    </ng-container>
  </div>
} @else {
  <h1>{{ value ?? "sampleVar is false" }}</h1>
}

Please provide a link to a minimal reproduction of the bug

https://github.com/lukasmatta/control-flow-migration-issue

Please provide the exception or error you saw


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


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