When and how can I get the length of a to-be-compiled div in Controller
and/or Directive
, the .length-wanted
in this case, without resorting to $timeout
? Or is there an event telling me that Angular's work is all done and I could go get its height/width?
<div ng-controller="testCtrl">
<div get-length>
<div class="length-wanted" ng-bind="arr"></div>
</div>
</div>
Demo here: http://jsfiddle.net/luxiyalu/tm54k4je/
Since it's possible that its size might change with resize, I eventually went with:
Directive:
Of course, this is checking the height of the element with every
$digest
. You could optimise this by storing aresized
property inscope
and returning the watched function if it's set to false.