title: Watch element's height in angular directive
body: <p>I'm trying to <code>$watch</code> an element's height in my directive's <code>link</code> function. </p>
  
  <p>The height of the element is set such that it's (eventually) equal to the window height. So it should change as the window is resized. </p>
  
  <p>However it isn't updating when you resize the window.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>angular.module('app', []).directive('element', function($interval) {
    return {
      restrict: 'E',
      link: function(scope, element) {
        scope.$watch(
          function() {
            return element.height();
          },
          function(height) {
            console.log('element updated', element.height());
          });
      },
    };
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>element {
    display: block;
    border: 1px dotted;
  }
  * {
    height: 100%;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"&gt;&lt;/script&gt;
  &lt;div ng-app="app"&gt;
    &lt;element&gt;test&lt;/element&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I <em>have</em> read this <a href="https://stackoverflow.com/questions/19048985/angularjs-better-way-to-watch-for-height-change">related question</a> but I don't understand why they're using 2 directives or how they're turning out to be helpful. I did try two <code>$watch</code>es, similar to what they have done there but it also doesn't help. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>angular.module('app', []).directive('element', function($interval) {
    return {
      restrict: 'E',
      link: function(scope, element) {
        scope.$watch('__height',
          function(height) {
            console.log('element updated', element.height());
          });
        scope.$watch(
          function() {
            scope.__height = element.height();
          });
      },
    };
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>element {
    display: block;
    border: 1px dotted;
  }
  * {
    height: 100%;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"&gt;&lt;/script&gt;
  &lt;div ng-app="app"&gt;
    &lt;element&gt;test&lt;/element&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>