Skip to content

Control flow - template used in multiple else clauses #52854

@kbrilla

Description

@kbrilla

Which @angular/* package(s) are relevant/related to the feature request?

No response

Description

When the same template is used in multiple*ngIf else clauses then te code is incorectly migrated

<div *ngIf="hasPermission; else noPermission">presentation</div>
<div *ngIf="someOtherPermission; else noPermission">presentation</div>
<ng-template #noPermission>
  <div>Imagine more than just some text</div>
</ng-template>
@if (hasPermission) {
<div>presentation</div>
} @else {

  <div>Imagine more than just some text</div>

}
@if (someOtherPermission) {
<div>presentation</div>
} @else {
#noPermission|
}
<ng-template #noPermission>
  <div>Imagine more than just some text</div>
</ng-template>

Proposed solution

  1. Use <ng-container *ngTemplateOutlet="noPermission"> and leave <ng-template #noPermission>

Alternatives considered

  1. Just duplicate template code and remove template

Not sure which is better so mayby allow for interactive migration and let user decide? Or at least flag for user preference.

Metadata

Metadata

Assignees

Labels

area: migrationsIssues related to `ng update`/`ng generate` migrationscore: control flowIssues related to the built-in control flow (@if, @for, @switch)

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions