I am working on a straightforward directive that I want to be able to execute a callback with parameters provided by the directive and the scope. Here is an example of what I am trying to achieve:
<div ng-repeat="user in users">
<div sample="..." callback="welcome(user, $message)">
</div>
</div>
I am encountering issues while using $parse to manage this functionality. The code for my sample directive looks like this:
app.directive('sample', ['$parse', function ($parse) {
return {
restrict: 'A',
scope: {},
link: function (scope, element, attrs) {
// ...
function greet () {
var callback = $parse(attrs.callback);
callback(scope, { $message: 'Howdy' });
}
},
},
}]);
However, despite successfully retrieving a function from $parse, executing it does not trigger my welcome function (defined in a controller) to be called (please note: using Angular 1.5.x). I suspect there might be an issue with the scope (possibly using the isolated scope instead of the parent scope) - but having an isolated scope is necessary for my requirements (simplified here for clarity). Can someone point me towards a solution?