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

feat($injector): allow loading of modules to an existing injector #1721

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/auto/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ function createInjector(modulesToLoad) {
}));


forEach(loadModules(modulesToLoad), function(fn) { instanceInjector.invoke(fn || noop); });
loadModules(modulesToLoad);

return instanceInjector;

Expand Down Expand Up @@ -478,14 +478,14 @@ function createInjector(modulesToLoad) {
////////////////////////////////////
// Module Loading
////////////////////////////////////
function loadModules(modulesToLoad){
function getModuleBlocks(modulesToLoad){
var runBlocks = [];
forEach(modulesToLoad, function(module) {
if (loadedModules.get(module)) return;
loadedModules.put(module, true);
if (isString(module)) {
var moduleFn = angularModule(module);
runBlocks = runBlocks.concat(loadModules(moduleFn.requires)).concat(moduleFn._runBlocks);
runBlocks = runBlocks.concat(getModuleBlocks(moduleFn.requires)).concat(moduleFn._runBlocks);

try {
for(var invokeQueue = moduleFn._invokeQueue, i = 0, ii = invokeQueue.length; i < ii; i++) {
Expand Down Expand Up @@ -519,6 +519,10 @@ function createInjector(modulesToLoad) {
return runBlocks;
}

function loadModules(modulesToLoad) {
forEach(getModuleBlocks(modulesToLoad), function(fn) { instanceInjector.invoke(fn || noop); });
}

////////////////////////////////////
// internal Injector
////////////////////////////////////
Expand Down Expand Up @@ -597,7 +601,8 @@ function createInjector(modulesToLoad) {
invoke: invoke,
instantiate: instantiate,
get: getService,
annotate: annotate
annotate: annotate,
load: loadModules
};
}
}