Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 11 additions & 6 deletions src/angularAMD.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/controllerFn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});

});
Expand Down