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:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Iβd say this should throw an error so that developers stop shadowing names.
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.