You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Control flow - template used in multiple else clauses #52854
area: migrationsIssues related to `ng update`/`ng generate` migrationscore: control flowIssues related to the built-in control flow (@if, @for, @switch)
Which @angular/* package(s) are relevant/related to the feature request?
No response
Description
When the same template is used in multiple*ngIfelse 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
Use <ng-container *ngTemplateOutlet="noPermission"> and leave <ng-template #noPermission>
Alternatives considered
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.
One more thing to consider, when template is used in both else clause and for ngTemplateOutlet then code inside tempalte is duplicated as well - so mayby here also flag or interactive migration could come in handy
@if (hasPermission) {
<div>presentation</div>
} @else {
<div>Imagine more than just some text</div>
}
<ng-container*ngTemplateOutlet="noPermission"></ng-container><ng-template#noPermission><div>Imagine more than just some text</div></ng-template>
area: migrationsIssues related to `ng update`/`ng generate` migrationscore: control flowIssues related to the built-in control flow (@if, @for, @switch)
Activity
kbrilla commentedon Nov 13, 2023
One more thing to consider, when template is used in both
elseclause and forngTemplateOutletthen code inside tempalte is duplicated as well - so mayby here also flag or interactive migration could come in handy@if (hasPermission) { <div>presentation</div> } @else { <div>Imagine more than just some text</div> } <ng-container *ngTemplateOutlet="noPermission"></ng-container> <ng-template #noPermission> <div>Imagine more than just some text</div> </ng-template>fix(migrations): Fixes issue with multiple if elses with same template
jessicajaniuk commentedon Nov 13, 2023
Thanks for reporting this! There's a fix in #52863.
fix(migrations): Fixes issue with multiple if elses with same template (
angular-automatic-lock-bot commentedon Dec 14, 2023
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.
fix(migrations): Fixes issue with multiple if elses with same template (
fix(migrations): Fixes issue with multiple if elses with same template (
fix(migrations): Fixes issue with multiple if elses with same template (
fix(migrations): Fixes issue with multiple if elses with same template (