My recommendation
First set the directive for the element you want to view height
Secondly, in the directive add an empty observer, as said in the doc , like this
If you want to be notified whenever $digest is called, you can register a watchExpression function with no listener.(Since watchExpression can execute multiple times per $digest cycle when a change is detected, be prepared for multiple calls to your listener.)
directive
scope.$watch( function(){ scope.elHeight = element.height();
Third, set the observer in the controller for this height
cotroller
$scope.$watch('elHeight', function(newVal, oldVal){ console.log(newVal, oldVal) };
Each set of $ digest means all Angular-related changes within the scope.
--- change ---
This covers most events related to Angular-js. However, it does not apply to manual resizing, i.e. resizing a window, resizing vanilla javascript, etc.
If I use AngularJS, I would fully use Angular throughout the page. Thus,
in this case, I would have missed a small event to get $ digest.
allenhwkim
source share