I have a controller registered like this:
myModule.controller(\'MyController\', function ($scope, ...some dependencies...)
{
....
Using
It appears that you can just use:
controller: 'MyController'
IF the controller is in the same module as the directive or a higher level module composed of the module with the directive in it.
When I tried it with two different modules composed into an app module (one for the controller and one for the directive), that did not work.
The answer you've already accepted works, and in almost all cases should be chosen...
For sake of completeness: Here is how you can use a controller from another module
(PS: Don't do this. lol :P)
var app = angular.module('myApp', ['myDirectives']);
app.controller('AppCtrl1', function($scope) {
$scope.foo = 'bar';
});
var directives = angular.module('myDirectives', []);
directives.directive('test', function($controller) {
return {
template: '<h1>{{foo}}</h1>',
link: function(scope, elem, attrs) {
var controller = $controller('AppCtrl1', { $scope: scope });
console.log($scope.foo); //bar
}
};
});