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

Control flow schematic: [ngIf] + [ngIfElse] + [ngTemplateOutlet] is not migrated properly #53288

Closed
mattlewis92 opened this issue Nov 30, 2023 · 3 comments
Assignees
Labels
area: migrations Issues related to `ng update` migrations core: control flow Issues related to the built-in control flow (@if, @for, @switch)
Milestone

Comments

@mattlewis92
Copy link
Contributor

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

core

Is this a regression?

No

Description

Input:

<ng-template
  [ngIf]="fooTemplate"
  [ngIfElse]="barTemplate"
  [ngTemplateOutlet]="fooTemplate"
></ng-template>

<ng-template #fooTemplate>Foo</ng-template>
<ng-template #barTemplate>Bar</ng-template>

Output:

@if (fooTemplate) {
  <ng-template
    [ngIfElse]="barTemplate"
    [ngTemplateOutlet]="fooTemplate"
  ></ng-template>
} @else {
  Bar
}
<ng-template #fooTemplate>Foo</ng-template>
<ng-template #barTemplate>Bar</ng-template>

Expected output ([ngIfElse]="barTemplate" should be removed):

@if (fooTemplate) {
  <ng-template
    [ngTemplateOutlet]="fooTemplate"
  ></ng-template>
} @else {
  Bar
}
<ng-template #fooTemplate>Foo</ng-template>
<ng-template #barTemplate>Bar</ng-template>

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

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

Angular CLI: 17.0.5
Node: 18.17.1
Package Manager: pnpm 8.11.0
OS: darwin arm64

Angular: 17.1.0-next.2+sha-1940280
... core

Package                             Version
-------------------------------------------------------------
@angular-devkit/architect           0.1700.1
@angular-devkit/build-angular       17.0.5
@angular-devkit/core                17.0.5
@angular-devkit/schematics          17.0.5
@angular/animations                 17.0.5
@angular/cdk                        17.0.1
@angular/cli                        17.0.5
@angular/common                     17.0.5
@angular/compiler                   17.0.5
@angular/compiler-cli               17.0.5
@angular/elements                   17.0.5
@angular/forms                      17.0.5
@angular/google-maps                15.2.9
@angular/language-service           17.0.5
@angular/localize                   17.0.5
@angular/platform-browser           17.0.5
@angular/platform-browser-dynamic   17.0.5
@angular/router                     17.0.5
@angular/service-worker             17.0.5
@schematics/angular                 17.0.5
ng-packagr                          17.0.2
rxjs                                7.8.0
typescript                          5.2.2
webpack                             5.88.2
zone.js                             0.14.2

Anything else?

I am using "@angular/core": "angular/core-builds#17.1.0-next.2+1940280", which is built from the HEAD of the main branch and contains all the latest control flow migration fixes.

@jessicajaniuk jessicajaniuk added area: migrations Issues related to `ng update` migrations core: control flow Issues related to the built-in control flow (@if, @for, @switch) labels Nov 30, 2023
@jessicajaniuk jessicajaniuk self-assigned this Nov 30, 2023
@ngbot ngbot bot modified the milestone: needsTriage Nov 30, 2023
jessicajaniuk pushed a commit to jessicajaniuk/angular that referenced this issue Nov 30, 2023
…ly removed

the attribute in question was assumed to be at the start of the replaced content, but it could be later, too.

fixes: angular#53288
@jessicajaniuk
Copy link
Contributor

Thanks! Fix is in #53298.

@jessicajaniuk
Copy link
Contributor

Also, your expected output is a hair off. The #barTemplate would be removed in this case since it's no longer needed.

@if (fooTemplate) {
  <ng-template
    [ngTemplateOutlet]="fooTemplate"
  ></ng-template>
} @else {
  Bar
}
<ng-template #fooTemplate>Foo</ng-template>

dylhunn pushed a commit that referenced this issue Dec 1, 2023
…ly removed (#53298)

the attribute in question was assumed to be at the start of the replaced content, but it could be later, too.

fixes: #53288

PR Close #53298
@dylhunn dylhunn closed this as completed in 1c1e8c4 Dec 1, 2023
tbondwilkinson pushed a commit to tbondwilkinson/angular that referenced this issue Dec 6, 2023
…ly removed (angular#53298)

the attribute in question was assumed to be at the start of the replaced content, but it could be later, too.

fixes: angular#53288

PR Close angular#53298
@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 Jan 1, 2024
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this issue Jan 23, 2024
…ly removed (angular#53298)

the attribute in question was assumed to be at the start of the replaced content, but it could be later, too.

fixes: angular#53288

PR Close angular#53298
rlmestre pushed a commit to rlmestre/angular that referenced this issue Jan 26, 2024
…ly removed (angular#53298)

the attribute in question was assumed to be at the start of the replaced content, but it could be later, too.

fixes: angular#53288

PR Close angular#53298
amilamen pushed a commit to amilamen/angular that referenced this issue Jan 26, 2024
…ly removed (angular#53298)

the attribute in question was assumed to be at the start of the replaced content, but it could be later, too.

fixes: angular#53288

PR Close angular#53298
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: migrations Issues related to `ng update` migrations core: control flow Issues related to the built-in control flow (@if, @for, @switch)
Projects
None yet
2 participants