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
Support optional chaining in template #149
Comments
Also happening on OS X 10.11.6 (El Capitan). OS: OS X 10.11.6 |
I also got this problem on Window 10 x64 |
Same problem here. OS: macOS 10.13 |
Same problem! Any solution? |
Should I import it in the app.module or in my component where the form is exist? |
The @angular/forms imports mentioned by @VladBozhinovski won't solve it. |
Yeah didn't work me either... |
i have same problem .... any solution ? |
Same Issue, has anyone found a fix? |
Same issue here. Any ideas yet? |
I also got this problem any solutions |
Same here. |
it seems like I'm not alone :) |
So many people got this problem. You guys can prevent it like 'email?.error.required' |
@Duanthse03268 this worked by removing the red line error but still get the following console error, any idea why ?
|
Make sure u import |
None of the solutions in this thread resolve the issue. I made an example as simple as possible to make sure nothing else was messing it up: FormModule and Validators have been imported from @angular/forms. I also tested this solution by @Duanthse03268, and not only does it not resolve the red line issue, it also causes an error in console when the state of myField changes (TypeError: Cannot read property 'required' of null) if used without the '?' after 'errors'. My implementation works without errors in the browser but retains the (supposedly incorrect) red line in editor (VSCode). Gists of the files in question (everything else you can simply 'ng new...' to reproduce): app.module.ts Versions: Extension: 0.1.7 |
Why did not you try to use 'myfield?.error.required' . |
I did try it, just as I wrote in my previous comment: "not only does it not resolve the red line issue, it also causes an error in console when the state of myField changes (TypeError: Cannot read property 'required' of null)". So, to elaborate, 'myField?.errors.required' does not work and causes the above error message to be displayed in console. The '?' has to be written after 'errors' in order to have this code work in browser without error message, yet does not solve the original issue of incorrect red line in editor. |
This is extremely annoying as the red lines are there still but the functionality works. I agree with joonashak as the solutions presented do not work and trying both formats do not resolve the issue. |
this worked for me: <div *ngIf="clientFirstName?.errors?.required I hope it helps you. |
Only workarounds :( |
IntelliJ throws the same error for me. But the implementation works even with the errors in the browser. Workaround by @Ahnset worked for me. Would like to know what is this syntax and how is it working now? |
I found that this error appears every time you reference a property which is defined as 'any'. Another workaround is using the bracket property annotation, clientFirstName?.errors['required'] which is also pretty stupid. |
Its getting worst, with the latest update of vscode, my file tree has become more like a christmas tree 🎄 |
@adickenscheidt thank you for the workaround. Works great, agree dumb for now. |
@boban984 |
I was glad to find the However... nobody is addressing the root cause of the problem, and it's been an issue with the language service for something like a year now. The |
three solutions:
I like the third best |
@boban984 Great solution and explanation |
thnks, works for me!. 👍🏼 |
This was the most elegant solution, and really works for all cases: myForm.hasError('required', 'myField'). Thanks @antonheck |
It works, but the best solution based on simplicity was offered by @boban984: "myField.hasError('required')". :) |
I solved this problem in this way:
I hope to be helpful. |
Perfect @bePericon this works for me! |
|
So after two years, it has not been fixed? 🤣 |
It's not a bug, it's exactly the way it should work |
If this is expected functionality, can the documentation be updated? (see here for one example). This clearly infers the raw property accessors of |
Actually is it fixed? I switched to hasError ages ago, but now I'm trying and failing to reproduce the error. |
@thw0rted so, upon retest with
Also, I have the same vsCode language extension, and I still see squigglies strangely. Going to stick with |
This removed the errors for me. For reference, the code worked even when the errors were outlined, I just don't like seeing red lines in my code. |
Yes putting in the key as a string removes the red lines. But you lose features like correct spelling and auto-completion with this. |
in addition to using hasError(), accessing a form's child control should use get() rather that dot access. e.g.
solution would be:
|
Same issue. f.email.errors.email.required Fails This worked for me: f['email'].errors.required |
Should be fixed with angular/angular#33884. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
in 0.1.4 on Windows 10
errors?.required
is highlighted as an errorThe text was updated successfully, but these errors were encountered: