Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8c4dd97

Browse files
squash-me!feat($injector): add new modules property
The `modules` property is a hash of the modules loaded into the injector at bootstrap time. This can be used to access the module's info.
1 parent 3ff0df4 commit 8c4dd97

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/auto/injector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ function createInjector(modulesToLoad, strictDi) {
699699
instanceInjector = protoInstanceInjector;
700700

701701
providerCache['$injector' + providerSuffix] = { $get: valueFn(protoInstanceInjector) };
702-
instanceInjector.modules = createMap();
702+
instanceInjector.modules = providerInjector.modules = createMap();
703703
var runBlocks = loadModules(modulesToLoad);
704704
instanceInjector = protoInstanceInjector.get('$injector');
705705
instanceInjector.strictDi = strictDi;

test/auto/injectorSpec.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,33 @@
33
/* globals support: false */
44

55
describe('injector.modules', function() {
6-
it('should expose the loaded module info', function() {
6+
it('should expose the loaded module info on the instance injector', function() {
77
var test1 = angular.module('test1', ['test2']).info({ version: '1.1' });
88
var test2 = angular.module('test2', []).info({ version: '1.2' });
99
module('test1');
10-
inject(function($injector) {
10+
inject(['$injector', function($injector) {
1111
expect(Object.keys($injector.modules)).toEqual(['ng', 'ngLocale', 'ngMock', 'test1', 'test2']);
1212
expect($injector.modules['test1'].info()).toEqual({ version: '1.1' });
1313
expect($injector.modules['test2'].info()).toEqual({ version: '1.2' });
14-
});
14+
}]);
15+
});
16+
17+
it('should expose the loaded module info on the provider injector', function() {
18+
var providerInjector;
19+
var test1 = angular.module('test1', ['test2']).info({ version: '1.1' });
20+
var test2 = angular.module('test2', [])
21+
.info({ version: '1.2' })
22+
.provider('test', ['$injector', function($injector) {
23+
providerInjector = $injector;
24+
return { $get: function() {} };
25+
}]);
26+
module('test1');
27+
// needed to ensure that the provider blocks are executed
28+
inject();
29+
30+
expect(Object.keys(providerInjector.modules)).toEqual(['ng', 'ngLocale', 'ngMock', 'test1', 'test2']);
31+
expect(providerInjector.modules['test1'].info()).toEqual({ version: '1.1' });
32+
expect(providerInjector.modules['test2'].info()).toEqual({ version: '1.2' });
1533
});
1634
});
1735

0 commit comments

Comments
 (0)