Call controller method from directive without defining it on the directive element - AngularJS

I'm sure there's a simple answer to this that i've just missed.

http://jsfiddle.net/jonathanwest/pDRxw/3/

Essentially, my directive will contain controls that will always call the same method in a controller which is external to the directive itself. As you can see from the above fiddle, I can make this work by defining the attribute with the method on the control directive, but as that method will always be called from the same button within the directive, I don't want to have to define the method to call. Instead the directive should know to call the controller edit method when that button is pressed. Therefore, the definition of the control would be:

<control title="Custom Title" />

How can I achieve this?

You can access the parent scope by using $parent property of the current scope.

http://jsfiddle.net/XEt7D/

Actually I think doing that straightway using $parent is not a recommended way how directives should be defined. Because actually there is no visible dependency on what functions could be called from parent controller, making them little bit harder to re-use.

I do not know actual use case why you need this, but I assume that you use control several times and you do not want to copy-paste bunch of attributes that defines some common behavior.

In this case I would recommend little bit other approach: add some directive-container that will define that behavior, and control will require this directive as dependency:

myApp.directive('controlBehavior', function() {
    return {
        restrict: 'E',
        scope: {
            modifyfunc: '&'
        },        
        controller: function($scope, $timeout) {
            this.modifyfunc = $scope.modifyfunc;
        }
    };
});
myApp.directive('control', function() {
    return {
        restrict: 'E',
        require: '^controlBehavior',
        replace: true,
        scope: {
            title: "@"
        },
        template : '<div>{{title}}<button ng-click="edit()">Edit</button></div>',
        link: function(scope, element, attr, behavior) {            
            scope.edit = behavior.modifyfunc;   
        }            
    }
});

Here is a fiddle to demonstrate this approach: http://jsfiddle.net/7EvpZ/4/