Honestly, no wonder they write that this is a difficult topic to understand. I did not understand, like most.
Where to use this thing?
Example:
.directive('clickable', function() { return { restrict: "E", link: function($scope, element, attrs) { element.bind('click', function() { $scope.$apply(function() { $scope.user++; $scope.bar++; }); console.log('1') }); } } }); Without the $scope.$apply() wrapper, the example will not work.
I do not know, I found this note:
Important: any browser events are raised outside of the AngularJS scope, so inside your event handlers you need to call $scope.$apply .