You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, only strings could be used as identifiers for Angular services. This commit adds support
for using any value as identifier for an Angular service (e.g. used with `.provider()`,
`.factory()`, `.service()`, `.value()`, `.constant()`, `.decorator()`).
Among other things, non-string identifiers enable:
- Private services (without relying on naming conventions).
- Collision avoidance (without relying on custom prefixes and namespacing).
- Better toolability (e.g. autocomplete support for service identifiers).
- Better compression (i.e. strings can't be minified, non-string values could).
Identifiers for directives and filters are still restricted to string values, since they need to be
referenced in HTML (text).
--
For services with string IDs, the corresponding provider ID is constructed by appending `Provider`
to the service ID. For services with non-string IDs, the corresponding provider has the exact same
ID (it is the context that determines if a service or a provider should be injected).
E.g.:
```js
var bar = {};
angular.
module('myModule', []).
provider('foo' /* string ID */, {$get: function () { return 'FOO'; }}).
provider( bar /* non-string ID */, {$get: function () { return 'BAR'; }}).
config(['fooProvider', function (fooProvider) {
// `foo` provider injected (because we are in config block)
}]).
run(['foo', function (foo) {
// `foo` service injected (because we are in run block)
}]).
config([bar, function (barProvider) {
// `bar` provider injected (because we are in config block)
// (even though we used the same identifier (`bar`) that we will use in the run block)
}]).
run([bar, function (bar) {
// `bar` service injected (because we are in run block)
}]);
```
--
This change is backwards compatible (afaict).
Fixesangular#10347
0 commit comments