title: Angular.js - Apply filter using an interval
body: <p>I am using a custom angular.js filter for datetime objects:</p>
  
  <pre><code>function relativeTimeFilter()
  {
      return function (dateObj) {
          return getRelativeDateTimeString(dateObj);
      };
  }
  
  function getRelativeDateTimeString(dt)
  {
      if(!dt) return "undefined ago";
  
      var delta = dt.getSeconds();
      if (delta &lt; 0) return "not yet";
      if (delta &lt; 1 * 60) return delta == 1 ? "one second ago" : delta + " seconds ago";
      if (delta &lt; 2 * 60) return "a minute ago";
      if (delta &lt; 45 * 60) return Math.floor(delta/60) + " minutes ago";
      if (delta &lt; 90 * 60) return "an hour ago";
      if (delta &lt; 24 * (60*60)) return Math.floor(delta/60/60) + " hours ago";
      if (delta &lt; 48 * (60*60)) return "yesterday";
      if (delta &lt; 30 * (24 * (60*60))) return Math.floor(delta/60/60/24) + " days ago";
      if (delta &lt; 12 * (30 * (24 * (60*60))))
      {
          var months = Math.floor(delta/60/60/24/30);
          return (months &lt;= 1) ? "one month ago" : (months + " months ago");
      }
      else
      {
          var years = Math.floor(delta/60/60/24/365);
          return (years &lt;= 1) ? "one year ago" : (years + " years ago");
      }
  }
  
  module.filter("relativetime", relativeTimeFilter);
  </code></pre>
  
  <p>At this point, it is not so important which filter I use (I think). The filter receives a Datetime object. The relative time declaration is only valid one second. Meaning <code>one second ago</code> must be updated after a second to <code>2 seconds ago</code> and so on.</p>
  
  <p>When I apply the filter, this only happens once. So how do I trigger the filter appliance in a regular interval?</p>
  
  <p>I tried the following:</p>
  
  <pre><code>setInterval(function() {$scope.$apply()}, 1000) // placed in controller function
  </code></pre>
  
  <p>...with no success.</p>
  
  <p>Any ideas?</p>