JSFiddle - React, Tailwind, and code Playground

by Gajus Kuizinas

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>

JavaScript

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);
});