diff --git a/src/angularAMD.js b/src/angularAMD.js index 2faa891..23b3e87 100644 --- a/src/angularAMD.js +++ b/src/angularAMD.js @@ -135,14 +135,19 @@ define(function () { delete config.controllerUrl; if (typeof config.controller === 'undefined') { // Only controllerUrl is defined. Attempt to set the controller to return value of package loaded. - config.controller = [ - '$scope', '__AAMDCtrl', '$injector', - function ($scope, __AAMDCtrl, $injector) { - if (typeof __AAMDCtrl !== 'undefined' ) { - $injector.invoke(__AAMDCtrl, this, { '$scope': $scope }); + var dependencies = ['__AAMDCtrl', '$injector', '$scope']; + angular.forEach(config.resolve, function(factory, key) { + dependencies.push(key); + }); + config.controller = dependencies.concat(function(__AAMDCtrl, $injector) { + if (typeof __AAMDCtrl !== 'undefined' ) { + var locals = {}; + for (var i = 2; i < dependencies.length; ++i) { + locals[dependencies[i]] = arguments[i]; } + $injector.invoke(__AAMDCtrl, this, locals); } - ]; + }); } } else if (typeof config.controller === 'string') { load_controller = config.controller; diff --git a/test/unit/controllerFn.spec.js b/test/unit/controllerFn.spec.js index ee5df39..9b12b7a 100644 --- a/test/unit/controllerFn.spec.js +++ b/test/unit/controllerFn.spec.js @@ -29,7 +29,7 @@ define(['angularAMD'], function (angularAMD) { expect(route.current.controller).toBeDefined(); // Make sure that controller has been set to custom function - expect(route.current.controller.toString()).toMatch(/^\$scope,__AAMDCtrl,\$injector,function/); + expect(route.current.controller.toString()).toMatch(/^__AAMDCtrl,\$injector,\$scope,function/); }); });