In my controller, after the click event, I add a directive to the page that will 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 configured it so that controllerFunc is called in the click event (via myfunc: &), and I'm trying to pass the click event through $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){
When I click on the appropriate div, controllerFunc is called in the controller, but the event is called undefined .
$scope.controllerFunc = function(e){
Is there a way to pass the event using ng-click in this situation (for example, where did I add the template in dom with the ng-click event? It seems to work (since the click event triggers the function), but there is no event in controllerFunc
angularjs
Leahcim
source share