I cannot figure out why my directive is not calling my callback function from my parent page. Can you please assist?
Angular code:
angular
.module('myApp')
.directive('testDirective', function () {
return {
bindToController: {
foo: '@',
myCallback: '&'
},
controller: function () {
},
controllerAs: 'vm',
restrict: 'E',
replace: true,
scope: {},
template: '<div>Foo is: {{ vm.foo }} <button data-ng-click="vm.myCallback()">Click to call Callback</button></div>'
};
});
angular
.module('myApp')
.controller('ParentController', function () {
this.myParentCallback = function () {
alert('Called the parent callback function');
};
});
HTML code:
<body>
<div data-ng-app="myApp" data-ng-controller="ParentController as ctrl">
<test-directive foo="bar!" my-callback="ctrl.myParentCallBack"></test-directive>
</div>
</body>
As you can see, foo binds correctly, but I can't get myCallback to work...
Thoughts?
Here it is in plnkr: (http://plnkr.co/edit/niVL5iAeOJ6XTpkpL9fu?p=preview)
myParentCallbackwhich exists inParentController.