I want to call the controller method after the directive made a change in the DOM, but it did not work, so I send this method in the directive, which is called inside scope.$watch
.directive('checkThis', function($timeout) {
return {
restrict: 'E',
scope: {
myData: '=',
dirty: '=',
what: '@',
callback: '&'
},
link: function(scope, element, attrs) {
scope.$watch('myData', function(newValue, oldValue) {
if (newValue !== oldValue) {
if (newValue) {
scope.dirty++;
} else {
scope.dirty--;
}
check();
}
});
var check = function () {
if (angular.isDefined(scope.callback)) {
$timeout(function() {
console.log('being called');
scope.callback();
}, 0, false);
}
};
}
};
});
and using this directive in HTML as shown below
<check-this my-data="vm.encryption" dirty="vm.dirty" what="column" callback="vm.checkAll()"></check-this>
now, when I use attrs.callback, it is not executed, but it scope.callback()is executed, even when I check attrs.callback, it displays the method in the console.
why is this behavior so?
even i tried scope.$eval(attrs.callback)and
scope.$apply(function() {
scope.$eval(attrs.callback);
});
but he is not called. I take the link from in this article
source
share