Im trying to send a message from within a directive to its parent controller (without success)
Here is my HTML
<div ng-controller="Ctrl">
<my-elem/>
</div>
Here is the code in the controller which listens for the event
$scope.on('go', function(){ .... }) ;
And finally the directive looks like
angular.module('App').directive('myElem',
function () {
return {
restrict: 'E',
templateUrl: '/views/my-elem.html',
link: function ($scope, $element, $attrs) {
$element.on('click', function() {
console.log("We're in") ;
$scope.$emit('go', { nr: 10 }) ;
}
}
}
}) ;
I've tried different scope configuration and $broadcast instead of $emit. I see that the event gets fired, but the controller does not receive a 'go' event. Any suggestions ?
$scope.$on('go', function(){ .... });
or is that a typo? – Dexterdexterity