Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
2010-10-09 00:30:13 +00:00
|
|
|
/**
|
2010-11-25 06:50:34 +00:00
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.injector
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Creates an inject function that can be used for dependency injection.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object=} [providerScope={}] provider's `this`
|
|
|
|
|
* @param {Object.<string, function()>=} [providers=angular.service] Map of provider (factory)
|
|
|
|
|
* function.
|
|
|
|
|
* @param {Object.<string, function()>=} [cache={}] Place where instances are saved for reuse. Can
|
|
|
|
|
* also be used to override services speciafied by `providers` (useful in tests).
|
|
|
|
|
* @returns {function()} Injector function.
|
|
|
|
|
*
|
|
|
|
|
* @TODO These docs need a lot of work. Specifically the returned function should be described in
|
|
|
|
|
* great detail + we need to provide some examples.
|
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
2010-10-09 00:30:13 +00:00
|
|
|
*/
|
|
|
|
|
function createInjector(providerScope, providers, cache) {
|
|
|
|
|
providers = providers || angularService;
|
|
|
|
|
cache = cache || {};
|
|
|
|
|
providerScope = providerScope || {};
|
|
|
|
|
/**
|
|
|
|
|
* injection function
|
|
|
|
|
* @param value: string, array, object or function.
|
|
|
|
|
* @param scope: optional function "this"
|
|
|
|
|
* @param args: optional arguments to pass to function after injection
|
|
|
|
|
* parameters
|
|
|
|
|
* @returns depends on value:
|
|
|
|
|
* string: return an instance for the injection key.
|
|
|
|
|
* array of keys: returns an array of instances.
|
|
|
|
|
* function: look at $inject property of function to determine instances
|
2010-11-15 20:15:27 +00:00
|
|
|
* and then call the function with instances and `scope`. Any
|
2011-01-19 23:42:11 +00:00
|
|
|
* additional arguments (`args`) are appended to the function
|
2010-11-15 20:15:27 +00:00
|
|
|
* arguments.
|
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
2010-10-09 00:30:13 +00:00
|
|
|
* object: initialize eager providers and publish them the ones with publish here.
|
|
|
|
|
* none: same as object but use providerScope as place to publish.
|
|
|
|
|
*/
|
|
|
|
|
return function inject(value, scope, args){
|
2011-01-04 18:40:34 +00:00
|
|
|
var returnValue, provider;
|
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
2010-10-09 00:30:13 +00:00
|
|
|
if (isString(value)) {
|
|
|
|
|
if (!cache.hasOwnProperty(value)) {
|
|
|
|
|
provider = providers[value];
|
|
|
|
|
if (!provider) throw "Unknown provider for '"+value+"'.";
|
|
|
|
|
cache[value] = inject(provider, providerScope);
|
|
|
|
|
}
|
|
|
|
|
returnValue = cache[value];
|
|
|
|
|
} else if (isArray(value)) {
|
|
|
|
|
returnValue = [];
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(value, function(name) {
|
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
2010-10-09 00:30:13 +00:00
|
|
|
returnValue.push(inject(name));
|
|
|
|
|
});
|
|
|
|
|
} else if (isFunction(value)) {
|
|
|
|
|
returnValue = inject(value.$inject || []);
|
|
|
|
|
returnValue = value.apply(scope, concat(returnValue, arguments, 2));
|
|
|
|
|
} else if (isObject(value)) {
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(providers, function(provider, name){
|
2011-01-04 18:40:34 +00:00
|
|
|
if (provider.$eager)
|
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
2010-10-09 00:30:13 +00:00
|
|
|
inject(name);
|
2011-01-04 18:40:34 +00:00
|
|
|
|
|
|
|
|
if (provider.$creation)
|
|
|
|
|
throw new Error("Failed to register service '" + name +
|
|
|
|
|
"': $creation property is unsupported. Use $eager:true or see release notes.");
|
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
2010-10-09 00:30:13 +00:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
returnValue = inject(providerScope);
|
|
|
|
|
}
|
|
|
|
|
return returnValue;
|
|
|
|
|
};
|
2010-12-10 21:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function injectService(services, fn) {
|
|
|
|
|
return extend(fn, {$inject:services});;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function injectUpdateView(fn) {
|
|
|
|
|
return injectService(['$updateView'], fn);
|
|
|
|
|
}
|