In my controller, upon a click event, I add a directive to the page, which is going to be able to call controllerFunc
$scope.addDirective = function(e, instance){
$scope.instance = instance;
$(e.currentTarget.parentElement).append($compile('<my-directive myfunc="controllerFunc($event)" mydata={{instance}}/>')($scope));
}
In my directive, I set it up so that controllerFunc gets called on a click event (via myfunc: &), and I try to pass the click event via $event
app.directive('myDirective',function(){
return {
restrict: 'AE',
scope: {
mydata: '@',
myfunc: "&"
},
template: '<div class="row"><div class="col-4" ng-click="myfunc($event)"></div></div>',
link: function(scope, elem, attrs){
//ommitted
}
}
}
When I click the relevant div, controllerFunc gets called in the controller but the event is said to be undefined.
$scope.controllerFunc = function(e){
//called on the click event but e is undefined
}
Is there a way to pass the event with ng-click in this situation (i.e. where I've added a template to the dom with an ng-click event? It seems like it should work (since the click event triggers the function) but there's no event in controllerFunc
ng-click="myfunc( { $event: $event} ). it should work.