-
Notifications
You must be signed in to change notification settings - Fork 27.4k
docs(*): clarify module API and dependency injection rules #16395
Conversation
docs/content/guide/di.ngdoc
Outdated
- {@link angular.Module#service Services}, {@link angular.Module#directive directives}, | ||
{@link angular.Module#filter filters}, and {@link angular.Module#animation animations} are | ||
defined by an injectable factory method or constructor function, and can be injected with | ||
"service" and "value" as dependencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would read better if we made it "services" and "values" (i.e. plural). Same below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you inject "constants" into services?
docs/content/guide/di.ngdoc
Outdated
|
||
- {@link ng.$controller Controllers} are defined by a constructor function, which can be injected | ||
with any of the "service" and "value" as dependencies, but they can also be provided with | ||
special dependencies. See {@link di#controllers Controllers} below for a list of these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, how about putting double quotes around "special dependencies"?
docs/content/guide/di.ngdoc
Outdated
- {@link angular.Module#service Services}, {@link angular.Module#directive directives}, | ||
{@link angular.Module#filter filters}, and {@link angular.Module#animation animations} are | ||
defined by an injectable factory method or constructor function, and can be injected with | ||
"service" and "value" as dependencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you inject "constants" into services?
docs/content/guide/di.ngdoc
Outdated
|
||
- The {@link angular.Module#config `config`} method accepts a function, which can be injected with | ||
"provider" and "constant" as dependencies. Note that you cannot inject "service" or | ||
"value" components into configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the components
from here.
docs/content/guide/di.ngdoc
Outdated
"provider" and "constant" as dependencies. Note that you cannot inject "service" or | ||
"value" components into configuration. | ||
|
||
- The {@link angular.Module#provider `provider`} method can only be injected with other "provider" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, I would just say "providers"
rather than "provder" injectables
, unless you change the rest to use the word injectables too.
docs/content/guide/di.ngdoc
Outdated
"value" components into configuration. | ||
|
||
- The {@link angular.Module#provider `provider`} method can only be injected with other "provider" | ||
injectables, and only with those that have been **registered beforehand**. This is different |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For emphasis, I would put and only with those that have been **registered beforehand
in its own sentence.
docs/content/guide/module.ngdoc
Outdated
during the bootstrap process. In its simplest form the module consists of a collection of two kinds | ||
of blocks: | ||
A {@link angular.Module module} is a collection of providers, services, directives etc., | ||
and optionally configuration and run blocks which get applied to the application during the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configuration => config ?
docs/content/guide/module.ngdoc
Outdated
}); | ||
``` | ||
See {@link guide/di#using-dependency-injection Using Dependency Injection} to find out which | ||
dependencies can be injected in which injectables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "in each method"?
docs/content/guide/module.ngdoc
Outdated
### Registering injectables in the config block | ||
|
||
While it is recommended to register injectables directly with the {@link angular.Module module API}, | ||
it is also possible to register services, directives etc. by injecting into the config function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is also possible to register ... via the $provide
function injected into a config block.
docs/content/guide/module.ngdoc
Outdated
executed in order of requirement. | ||
|
||
Note that each module is only loaded once, even if multiple other modules require it. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth adding that factories for services, etc are only called lazily when the service is injected for the first time.
c925775
to
ba450ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Closes #16363
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behavior? (You can also link to an open issue here)
What is the new behavior (if this is a feature change)?
Does this PR introduce a breaking change?
Please check if the PR fulfills these requirements
Other information: