Skip to content

Commit 4a498c3

Browse files
mprobstnetman92
authored andcommitted
fix(injector): check that modulesToLoad isArray.
When users accidentally just pass a single string, e.g. `angular.injector('myModule')`, this change give them a better error message. Currently Angular just reports that the module with the name 'm' is missing, as it's iterating through all characters in the string, instead of all strings in the module. Closes angular#12285
1 parent a1140c9 commit 4a498c3

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/auto/injector.js

+1
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ function createInjector(modulesToLoad, strictDi) {
718718
// Module Loading
719719
////////////////////////////////////
720720
function loadModules(modulesToLoad) {
721+
assertArg(isUndefined(modulesToLoad) || isArray(modulesToLoad), 'modulesToLoad', 'not an array');
721722
var runBlocks = [], moduleFn;
722723
forEach(modulesToLoad, function(module) {
723724
if (loadedModules.get(module)) return;

test/auto/injectorSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ describe('injector', function() {
3535
});
3636

3737

38+
it('should check its modulesToLoad argument', function() {
39+
expect(function() { angular.injector('test'); })
40+
.toThrowMinErr('ng', 'areq');
41+
});
42+
43+
3844
it('should resolve dependency graph and instantiate all services just once', function() {
3945
var log = [];
4046

0 commit comments

Comments
 (0)