question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ivy ngFor wont over ride variable in scope

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by the new Ivy renderer.

Is this a regression?

Yes, it is working as expected when ivy isn't enabled.

Description

the variable name used for the variable in the ngFor loop can no longer be the same as the variable you’re using within the ngFor from the component.

πŸ”¬ Minimal Reproduction

using @angular/cli@8.0.0-rc.4 create a new project. Add a property to the AppComponent someClass: any;

Add the following to the html template of the component.

<div *ngFor='let someClass of someClass.children' >

</div>

enable ivy run ng build --aot

It doesn’t matter the type of someClass. Let it be any. It appears that ivy can’t differentiate between the someClass in let someClass and someClass in someClass.children.

The code won’t compile unless you change the name to something different. Like this.

<div *ngFor='let someClass2 of someClass.children' >

</div>
https://stackblitz.com/edit/angular-eurwqh

I’m not sure how to get stack blitz to run with the --aot flag. So here’s a git repo with the same code. https://github.com/e-davidson/angular-ivy-issue

πŸ”₯ Exception or Error





ERROR in : Error: Could not resolve [object Object] / undefined
    at Scope.resolve (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:549:23)
    at tcbResolve (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:827:34)
    at C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:755:74
    at astToTypescript (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\expression.js:47:24)
    at astToTypescript (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\expression.js:59:28)
    at Object.astToTypescript (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\expression.js:54:20)
    at tcbExpression (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:755:29)
    at processAttribute (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:802:28)
    at Array.forEach (<anonymous>)
    at tcbGetInputBindingExpressions (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:792:30)
    at TcbDirectiveOp.execute (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:300:28)
    at Scope.executeOp (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:622:26)
    at Scope.render (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:561:22)
    at Object.generateTypeCheckBlock (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_block.js:43:37)
    at TypeCheckFile.addTypeCheckBlock (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\type_check_file.js:47:41)
    at TypeCheckContext.addTemplate (C:\Users\edavidson\src\temp\MatSortUpdateIssue\MatSortUpdateIssue\node_modules\@angular\compiler-cli\src\ngtsc\typecheck\src\context.js:98:36)

🌍 Your Environment

Angular Version:




Angular CLI: 8.0.0-rc.4
Node: 12.3.1
OS: win32 x64
Angular: 8.0.0-rc.5
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.0-rc.4
@angular-devkit/build-angular     0.800.0-rc.4
@angular-devkit/build-optimizer   0.800.0-rc.4
@angular-devkit/build-webpack     0.800.0-rc.4
@angular-devkit/core              8.0.0-rc.4
@angular-devkit/schematics        8.0.0-rc.4
@angular/cli                      8.0.0-rc.4
@ngtools/json-schema              1.2.0
@ngtools/webpack                  8.0.0-rc.4
@schematics/angular               8.0.0-rc.4
@schematics/update                0.800.0-rc.4
ng-packagr                        5.2.0
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.30.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Airbladercommented, May 26, 2019

I’d say this should throw an error so that developers stop shadowing names.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 15, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

scope of *ngFor let variable - angular - Stack Overflow
I know I can use a component in between to resolve the issue. I just want to know if nested fors are possible...
Read more >
A quick intro to Angular Ivy | Abitrarily Idiosyncratic Randomness
Ivy renderer won't be default in Angular v6. You need to manually enable it by switching on certain compiler option.
Read more >
NgFor - Angular
The ngForOf directive is generally used in the shorthand form *ngFor . ... NgForOf provides exported values that can be aliased to local...
Read more >
How to Avoid Observables in Angular - DEV Community ‍ ‍
As reactive programming is hard for an imperative thinking mind, many people try to avoid it. This article will help us to understand...
Read more >
Dependency injection in action - Angular
You can limit the scope of an injected service to a branch of the ... @Component({ selector: 'app-unsorted-heroes', template: `<div *ngFor="let hero ofΒ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found