MCPcopy
hub / github.com/angular-ui/ui-router / createInjector

Function createInjector

test/angular/1.7/angular.js:4905–5172  ·  view source on GitHub ↗

* @ngdoc method * @name $provide#decorator * @description * * Register a **decorator function** with the auto.$injector $injector. A decorator function * intercepts the creation of a service, allowing it to override or modify the behavior of the * service. The return value of the decor

(modulesToLoad, strictDi)

Source from the content-addressed store, hash-verified

4903
4904
4905function createInjector(modulesToLoad, strictDi) {
4906 strictDi = (strictDi === true);
4907 var INSTANTIATING = {},
4908 providerSuffix = 'Provider',
4909 path = [],
4910 loadedModules = new NgMap(),
4911 providerCache = {
4912 $provide: {
4913 provider: supportObject(provider),
4914 factory: supportObject(factory),
4915 service: supportObject(service),
4916 value: supportObject(value),
4917 constant: supportObject(constant),
4918 decorator: decorator
4919 }
4920 },
4921 providerInjector = (providerCache.$injector =
4922 createInternalInjector(providerCache, function(serviceName, caller) {
4923 if (angular.isString(caller)) {
4924 path.push(caller);
4925 }
4926 throw $injectorMinErr('unpr', 'Unknown provider: {0}', path.join(' <- '));
4927 })),
4928 instanceCache = {},
4929 protoInstanceInjector =
4930 createInternalInjector(instanceCache, function(serviceName, caller) {
4931 var provider = providerInjector.get(serviceName + providerSuffix, caller);
4932 return instanceInjector.invoke(
4933 provider.$get, provider, undefined, serviceName);
4934 }),
4935 instanceInjector = protoInstanceInjector;
4936
4937 providerCache['$injector' + providerSuffix] = { $get: valueFn(protoInstanceInjector) };
4938 instanceInjector.modules = providerInjector.modules = createMap();
4939 var runBlocks = loadModules(modulesToLoad);
4940 instanceInjector = protoInstanceInjector.get('$injector');
4941 instanceInjector.strictDi = strictDi;
4942 forEach(runBlocks, function(fn) { if (fn) instanceInjector.invoke(fn); });
4943
4944 instanceInjector.loadNewModules = function(mods) {
4945 forEach(loadModules(mods), function(fn) { if (fn) instanceInjector.invoke(fn); });
4946 };
4947
4948
4949 return instanceInjector;
4950
4951 ////////////////////////////////////
4952 // $provider
4953 ////////////////////////////////////
4954
4955 function supportObject(delegate) {
4956 return function(key, value) {
4957 if (isObject(key)) {
4958 forEach(key, reverseParams(delegate));
4959 } else {
4960 return delegate(key, value);
4961 }
4962 };

Callers 1

doBootstrapFunction · 0.70

Calls 6

supportObjectFunction · 0.70
createInternalInjectorFunction · 0.70
valueFnFunction · 0.70
createMapFunction · 0.70
loadModulesFunction · 0.70
forEachFunction · 0.70

Tested by

no test coverage detected