title: Watch element value in angular
body: <p>I need to create a directive that i want to use like so:</p>
  
  <pre><code>&lt;div before-today="old"&gt;{{exampleDate}}&lt;/div&gt;
  </code></pre>
  
  <p>I want my directive to determine if the date inside the div is before "today", and if so, apply the class "old". My main problem is that "exampleDate" gets populated from an AJAX call, so at link time the value is empty. Any suggestions? This is what I have so far (not working):</p>
  
  <pre><code>angular.module('myApp').directive('beforeToday', [
    function () {
      return {
          restrict: 'A',
      scope: {
  
      },
        link: function (scope, element, attr) {
          var date = new Date(element.text());
          var today = new Date();
          if (today &gt;= date) {
            element.addClass(attr.beforeToday);
          }
        } 
      };
    }
  ]);
  </code></pre>