-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Description
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 => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
The documentation of Injectable says:
A marker metadata that marks a class as available to Injector for creation.
[...]
Injector will throw NoAnnotationError when trying to instantiate a class that does not have@Injectablemarker
The CLI also adds Injectable to all the services it creates, and the tutorial explains that a service must have this annotation.
However, a simple experiment with a component using a service not annotated with Injectable works fine (see http://plnkr.co/edit/IJVf79C1D8bNVLg9Kh2f?p=preview for example). It seems that the Injectable annotation is actually only needed if the service itself has dependencies that must be injected in its constructor, but that doesn't match with what the documentation says.
Expected behavior
angular should throw an error when an injector is trying to create an instance of a service not decorated with Injectable. Or the documentation should be fixed to explain what Injectable really is for.
Minimal reproduction of the problem with instructions
Launch this plunkr: http://plnkr.co/edit/IJVf79C1D8bNVLg9Kh2f?p=preview. Note that FooService is successfully created by the injector and injected into the app component, even though it doesn't have the Injectable decorator.
What is the motivation / use case for changing the behavior?
Make the documentation match the actual behavior of angular, or vice-versa
Please tell us about your environment:
NA. Happens on all environments.
-
Angular version: 2.0.X
-
Browser: all
-
Language: TypeScript