Ensuring the correct context when binding a callback function to a directive is crucial. When working with an isolated scope, this task is easily accomplished.
<bar-foo callback="mycontroller.callback()"></bar-foo>
The directive code:
...
scope:{
callback: '&'
},
...
If there is no isolated scope, I extract the callback from the $attrs attribute:
$scope.callback = $parse($attrs.callback)($scope);
However, in such cases I cannot simply use:
<bar-foo callback="mycontroller.callback()"></bar-foo>
This would lead to executing the callback directly. What would be the most recommended solution for this issue?