I have a specific directive code:
.directive('myDirective', function(){
'use strict';
return {
restrict: 'A'
, link: function(scope, element, attrs) {
var count = 0;
function doSomething() {
console.log('==== executing ====');
return { 'count' : count };
}
scope.$on('Test', function(event) {
count += 1;
console.log('++++broadcast received++++ phase:', scope.$$phase);
});
scope.$watch(doSomething(), function () {
console.log('-----Seen-----');
});
}
};
})
While broadcasting from a controller in a different scope, the "$on" function is able to receive the broadcast and log the entry successfully. However, the $watch function is not triggering when this happens. The "doSomething" function is not being called at all. The $$phase reports $apply as well.
What mistakes am I making here?