-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Improve error message for when Injectable() is missing #12467
Comments
Closes angular#12467 Closes angular#13820
BREAKING CHANGE: Before: class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } After: @Injectable() class SomeClass {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } Closes angular#12467 Closes angular#13820
BREAKING CHANGE: Before this commit it was not nessesary to add @Injectable for contructors without args or if any other decorator was applied. After this commit @Injectable is mandatory for all providers provided using useClass. Before: class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } After: @Injectable() class SomeClass {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } Closes angular#12467 Closes angular#13820 feat(compiler): wip feat(compiler): wip feat(compiler): wip
BREAKING CHANGE: Before this commit it was not nessesary to add @Injectable for contructors without args or if any other decorator was applied. After this commit @Injectable is mandatory for all providers provided using useClass. Before: class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } After: @Injectable() class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } Closes angular#12467 Closes angular#13820 feat(compiler): wip feat(compiler): wip feat(compiler): wip feat(compiler): wip
BREAKING CHANGE: Before this commit it was not nessesary to add @Injectable when a service had contructor without args or if any other decorator was applied. After this commit @Injectable is mandatory for all services provided using useClass. Before: class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } After: @Injectable() class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } Closes angular#12467 Closes angular#13820
BREAKING CHANGE: Before this commit it was not nessesary to add @Injectable when a service had contructor without args or if any other decorator was applied. After this commit @Injectable is mandatory for all services provided using useClass. Before: class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } After: @Injectable() class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } Closes angular#12467 Closes angular#13820
BREAKING CHANGE: Before this commit it was not nessesary to add @Injectable when a service had contructor without args or if any other decorator was applied. After this commit @Injectable is mandatory for all services provided using useClass. Before: class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } After: @Injectable() class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } Closes angular#12467 Closes angular#13820
BREAKING CHANGE: Before this commit it was not nessesary to add @Injectable when a service had contructor without args or if any other decorator was applied. After this commit @Injectable is mandatory for all services provided using useClass. Before: class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } After: @Injectable() class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } Closes angular#12467 Closes angular#13820
BREAKING CHANGE: Before this commit it was not nessesary to add @Injectable when a service had contructor without args or if any other decorator was applied. After this commit @Injectable is mandatory for all services provided using useClass. Before: class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } After: @Injectable() class SomeService {} @component({selector: 'my-app', template: ''}) class AppComponent { constructor(service: SomeService) {} } Closes angular#12467 Closes angular#13820
This issue I have faced in current angular cli version 1.7 |
Same, while injecting PS: Hmm... Router doesn't seem to have it either (and I can inject that just fine.) I'll look into creating a new issue (if one regarding this doesn't exist already.) PPS: Reloading vscode ( |
The error message is much more specific with Angular v9 running ivy, ex.:
|
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. |
I'm submitting a ...
Current behavior
If component A has a dependency on service B, but service B does not have the
Injectable()
decorator defined, a vague error message is thrown:This is the exact same error message for when dependencies can't be loaded. Up until now that error message was given because I use barrel files and the order of import/exports should be adjusted. Thus, I was thrown off when trying to fix this problem.
Expected behavior
A specific error message like:
Minimal reproduction of the problem with instructions
Create a service, but omit the
Injectable()
decorator. This service should have a dependency to at least one other service (defined correctly).Provide the services with the module.
Create a component that gets the
SomeService
injected.I used the Plnkr of the Angular quickstart to reproduce this problem. On the
Car
service inapp/car/car.ts
, I simply removed the decorator. The console immediately shows the error:// Edit:
In the documentation, it is mentioned that the injector will throw a
NoAnnotationError
, but the link toNoAnnotationError
results in a 404.What is the motivation / use case for changing the behavior?
A more precise error message would direct me to the problem instantly and the problem could have been fixed in a matter of seconds. Because this message is the exact same as when dependencies can't be resolved due to import/export order with barrel files, it now took me 30 minutes of stripping dependencies and order checking before I noticed this simple and tiny mistake.
Please tell us about your environment:
Windows 10, Chrome 53 and SystemJS as the module loader.
CompileMetadataResolver
and I'm not able to find a more specific error message.The text was updated successfully, but these errors were encountered: