Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

docs(*): clarify module API and dependency injection rules #16395

Merged
merged 2 commits into from
Jan 17, 2018

Conversation

Narretz
Copy link
Contributor

@Narretz Narretz commented Jan 8, 2018

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

  • The commit message follows our guidelines
  • Fix/Feature: Docs have been added/updated
  • Fix/Feature: Tests have been added; existing tests pass

Other information:

@Narretz Narretz added this to the 1.6.9 milestone Jan 8, 2018
- {@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.
Copy link
Contributor

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.

Copy link
Contributor

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?


- {@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
Copy link
Contributor

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"?

- {@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.
Copy link
Contributor

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?


- 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.
Copy link
Contributor

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.

"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"
Copy link
Contributor

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.

"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
Copy link
Contributor

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.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configuration => config ?

});
```
See {@link guide/di#using-dependency-injection Using Dependency Injection} to find out which
dependencies can be injected in which injectables.
Copy link
Contributor

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"?

### 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
Copy link
Contributor

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.

executed in order of requirement.

Note that each module is only loaded once, even if multiple other modules require it.

Copy link
Contributor

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.

@Narretz Narretz force-pushed the docs-provider-registration branch from c925775 to ba450ab Compare January 12, 2018 11:50
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Narretz Narretz merged commit a7e5e83 into angular:master Jan 17, 2018
@Narretz Narretz deleted the docs-provider-registration branch January 17, 2018 11:00
Narretz added a commit to Narretz/angular.js that referenced this pull request Jan 17, 2018
Narretz added a commit that referenced this pull request Jan 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 1.5.11 - Providers must be declared in correct sequence or injection fails
3 participants