I am creating a drag directive to add an event listener to the dragstart event. I want to pass a function from my controller to the directive. When I add the event listener it will not invoke the passed in function.
Here is my controller:
angular.module('testApp').controller('testCtrl', [testCtrl]);
function testCtrl() {
var vm = this;
vm.dragStart = dragStart;
function dragStart(e){
alert('drag started!', e);
}
}
Here is my directive:
angular.module('testApp').directive('testDraggable', function(){
var directive = {
scope: {
dragStart: '&',
},
restrict: 'A',
link: link
};
function link(scope, element, attrs){
var dragStartCallback = function(event){
alert('dragStartCallback!');
scope.dragStart({e: event});
}
element[0].addEventListener('dragstart', dragStartCallback, false);
}
return directive;
});
The issue I am having is that the dragStartCallback function is called but the inner scope.dragStart function is never called. I've read about mapping the parameters which is what I'm doing and it is still failing. In the dragStartCallback I am getting the event passed in properly as well. If there is a better way to go about doing this any advice would be appreciated.
Thanks in advance for any of your input. There is a JS Fiddle here: http://jsfiddle.net/6sk4dbre/