var injector;
angular
.module('a', ['b'])
.value('foo', 'FOO');
angular
.module('b', [])
.value('bar', 'BAR');
angular.injector(['a']).invoke(function (foo) {
console.log('Injector resolves a module.', foo);
});
angular.injector(['a']).invoke(function (bar) {
console.log('Injector resolves explicitly defined module dependencies.', bar);
});
try {
angular.injector(['a']).invoke(function ($document) {});
} catch (e) {
console.log('All dependencies must be defined explicitly when using angular.injector() (ng module is missing).');
}
angular
.module('a')
.run(function ($injector, foo, bar, $document) {
console.log('It unusual to obtain an instance of $injector. Angular DI will use an instance of $injector when defining components or when providing run and config blocks for a module, including for the resolution of the $injector itself.', typeof $injector, foo, bar, typeof $document);
});
injector = angular.bootstrap(document.createElement('div'), ['a']);
injector.invoke(function (foo, bar, $document) {
console.log('When app is bootstrapped (the imperative equivalent of using the ngApp directive), an instance of $injector is returned that resolves all user-defined modules, including the "ng" module.', foo, bar, typeof $document);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.