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

Commit

Permalink
fix(injector): check that modulesToLoad isArray.
Browse files Browse the repository at this point in the history
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 #12285
  • Loading branch information
mprobst authored and lgalfaso committed Aug 3, 2015
1 parent 9efe60f commit 5abf593
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/auto/injector.js
Expand Up @@ -718,6 +718,7 @@ function createInjector(modulesToLoad, strictDi) {
// Module Loading
////////////////////////////////////
function loadModules(modulesToLoad) {
assertArg(isUndefined(modulesToLoad) || isArray(modulesToLoad), 'modulesToLoad', 'not an array');
var runBlocks = [], moduleFn;
forEach(modulesToLoad, function(module) {
if (loadedModules.get(module)) return;
Expand Down
6 changes: 6 additions & 0 deletions test/auto/injectorSpec.js
Expand Up @@ -35,6 +35,12 @@ describe('injector', function() {
});


it('should check its modulesToLoad argument', function() {
expect(function() { angular.injector('test'); })
.toThrowMinErr('ng', 'areq');
});


it('should resolve dependency graph and instantiate all services just once', function() {
var log = [];

Expand Down

0 comments on commit 5abf593

Please sign in to comment.