Repository navigation
fix: better error messages for NgFor #14641
Description
Activity
pls add a plunkr
@DzmitryShylovich added to the description.
- addedarea: coreIssues related to the framework runtimeIssues related to the framework runtimeopen for contributionsAn issue that is suitable for a community contributor (based on its complexity/scope).An issue that is suitable for a community contributor (based on its complexity/scope).
on Feb 23, 2017 @vicb is
item of itemsa valid expression? I'm trying to figure out the right place for the fix. I thinkParsershould throwHello! some news about it? I have the same error
@BrunoViera to fix this change
<ANY *ngFor="item of items"></ANY>into<ANY *ngFor="let item of items"></ANY>the part you were missing was thelet.
This issue however is about improving the error messages that it throws when this situation does occurSo I gave at shot at a fix for this. Bear in mind that this is my first time doing something like this so feel free to just shut me down if I'm wrong :) I'm not entirely sure how to link the pull request I made :( But it is the only pull request in the compiler-builds repo
@eldaromer any PR to Angular should be made in this repo
eg https://github.com/angular/angular/pulls@Toxicable sorry, I'll delete the other one and fix it, thank you!
Same with 'ngIf' directive. You get same message if directive syntax is messed up.
Plunker: https://plnkr.co/edit/y1R2KaRRnfMFXJH2mCe1@eldaromer @Toxicable Is this fixed, or can I take a look at it?
@Math3v it's not fixed, feel free to make a PR for it
@Toxicable PR is in place.
Reacted by Baklazan, Oleksandr Tytskyi and Shai Reznik- removedopen for contributionsAn issue that is suitable for a community contributor (based on its complexity/scope).An issue that is suitable for a community contributor (based on its complexity/scope).
on May 19, 2020 - addedP4A relatively minor issue that is not relevant to core functionsA relatively minor issue that is not relevant to core functionsand removed
on Oct 1, 2020 This issue should now be fixed with a new extended template diagnostic.
angular-automatic-lock-bot commented
on Sep 8, 2022 More actionsThis 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.
- locked and limited conversation to collaborators
on Sep 8, 2022
I'm submitting a ... (check one with "x")
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request
Current behavior
While there have been a lot of improvements in the error messages space in Angular, it turns out that there's one case left that can causes many hours of debugging, because the error message is confusing.
When forgetting the
letkeyword inNgFor's micro syntax, that error message points the developer in a wrong direction. Basically, doing this:Throws this error:
This error messages usually occurs when one forgets to add/export a directive/component (in this case
NgFor), but the actually issue is that the developer forgot theletkeyword in the micro syntax.Unfortunately this caused me once 1.5 hours of debugging and wondering why Angular thinks I haven't declared
NgForanywhere, while it is in fact properly setup.I'm seeing more and more people running into this, so I thought it's worth bringing up.
Expected behavior
It would be cool if we can throw a more specific error message, or maybe extend the existing one to tell the developer that she needs to double-check the micro syntax.
**Plunker for reproduction
https://plnkr.co/edit/SAI2cYUjuiVXcg4sL8vz?p=preview (check the console)