-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Closed
Labels
area: migrationsIssues related to `ng update`/`ng generate` migrationsIssues related to `ng update`/`ng generate` migrationscore: control flowIssues related to the built-in control flow (@if, @for, @switch)Issues related to the built-in control flow (@if, @for, @switch)
Milestone
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
When ngSwitchCase is used without * or [], the @angular/core:control-flow schematic produces code that doesn't compile:
<ng-container [ngSwitch]="value">
<ng-template ngSwitchCase="">empty string</ng-template>
<ng-template ngSwitchCase="foo">"foo"</ng-template>
</ng-container>gets converted to
@switch (value) {
@case () {
empty string
}
@case (foo) {
"foo"
}
}when it should be
@switch (value) {
@case ('') {
empty string
}
@case ('foo') {
"foo"
}
}Please provide a link to a minimal reproduction of the bug
https://github.com/P4/ng-control-flow-migration/blob/master/src/app/app.component.ts
Please provide the exception or error you saw
Application bundle generation failed. [2.297 seconds]
✘ [ERROR] NG5002: @case block must have exactly one parameter [plugin angular-compiler]
src/app/app.component.ts:10:2:
10 │ @case () {
╵ ~~~~~~~~~~
✘ [ERROR] NG9: Property 'foo' does not exist on type 'AppComponent'. [plugin angular-compiler]
src/app/app.component.ts:13:9:
13 │ @case (foo) {
╵ ~~~
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 18.0.0
Node: 20.9.0
Package Manager: npm 10.1.0
OS: linux x64
Angular: 18.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1800.0
@angular-devkit/build-angular 18.0.0
@angular-devkit/core 18.0.0
@angular-devkit/schematics 18.0.0
@schematics/angular 18.0.0
rxjs 7.8.1
typescript 5.4.5
zone.js 0.14.6
Anything else?
We encountered this when migrating a real project at work, there's a more practical example in the linked repo based on the real code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: migrationsIssues related to `ng update`/`ng generate` migrationsIssues related to `ng update`/`ng generate` migrationscore: control flowIssues related to the built-in control flow (@if, @for, @switch)Issues related to the built-in control flow (@if, @for, @switch)