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

Scope of template local variables in Angular @if() block seems wrong #55783

Closed
alcfeoh opened this issue May 13, 2024 · 3 comments
Closed

Scope of template local variables in Angular @if() block seems wrong #55783

alcfeoh opened this issue May 13, 2024 · 3 comments

Comments

@alcfeoh
Copy link
Contributor

alcfeoh commented May 13, 2024

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

compiler

Is this a regression?

Yes

Description

If I declare a local template variable in an @if() block, such variable is available in the @if() block but not in the @else() block, which seems like a bug. See cartContents below is not available in my @else block (see variable name in red below):

Screenshot 2024-05-13 124310

Please provide a link to a minimal reproduction of the bug

Screenshot has an example

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.3.0
Node: 18.17.1
Package Manager: npm 10.5.1
OS: win32 x64

Angular: 17.3.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.0
@angular-devkit/build-angular   17.3.0
@angular-devkit/core            17.3.0
@angular-devkit/schematics      17.3.0
@schematics/angular             17.3.0
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.4

Anything else?

No response

@JeanMeche
Copy link
Member

JeanMeche commented May 13, 2024

Hi, this is as designed. Have a look at the RFC. Also note that aliasing is only supported because of the backward compatibility with *ngIf. See also #52103

What you are looking for is the longly awaited template variable declaration #15280.

@JeanMeche JeanMeche closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
@alcfeoh
Copy link
Contributor Author

alcfeoh commented May 13, 2024

Ok. Now that the syntax looks like regular if—then—else blocks, my expectation was that this would behave just like in other programming languages. I guess that's one more reason to use Signals instead of Observables.

@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 Jun 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants