AngularJS Directive Callback
angularjs, angularjs-directive
Solution
Tricky tricky angular, when declaring the argument in the HTML, it needs to use snake case, instead of camelcase to match.
Works:
<hello-world on-load-callback="myCallback(arg1)"></hello-world>
Doesn't Work:
<hello-world onLoadCallback="myCallback(arg1)"></hello-world>
Problem
I would like to send a call back into a directive via a parameter on the tag, and then call that method when appropriate inside the directive. For example, when a button was clicked call a method on the parent controller. I have a simple plunker of it not working html file: ``` <body ng-controller="ParentController"> <h1> Method Arguments </h1> <h3> open console to view output</h3> <hello-world onLoadCallback="myCallback(arg1)"></hello-world> </body> ``` javascript file: ``` var app = angular.module("app",[]); function ParentController($scope) { $scope.myCallback = function(var1){ console.log("myCallback", var1); } } app.directive('helloWorld', function() { return { restrict: 'AE', template: '<h3>Hello World!!</h3>', scope:{ onLoadCallback: '&' }, link: function(scope, element, attrs, dateTimeController) { console.log('linked directive, not calling callback') scope.onLoadCallback('wtf'); } }; }); ```