Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you could try using the $timeout in angular in order to poll the data from your server on a regular basis (like 30 minutes or less in your case)</p> <p>As it was not possible to create an example without your data, and I didn't want to stay 30 minutes in order to see if it worked, I made you this fiddle : <a href="http://jsfiddle.net/DotDotDot/mgSWt/3/" rel="nofollow">http://jsfiddle.net/DotDotDot/mgSWt/3/</a> , it simulates the query of data ( what you do with $http ) and then analyze it in order to display only the items within the time limit</p> <p>To be more precise, I create 3 variables at the beginning of the controller, corresponding to the time the page loaded, one, and two minutes before (but it's easy to pass it to 30 minutes) : </p> <pre><code>var n=new Date() var onemin=n.getTime()-60*1000//one min from now var twomin=n.getTime()-60*1000*2//two min from now </code></pre> <p>After that, I create a function to get the data ( with your example, I think it could be better with a service, but that's another question). This function will get the whole data (at least hard code it in my example) and check which items are to show or not. Then I call this function , and the function itself schedule the next execution time, on my example, every second (what you should set to another value, 30 min, less, it will depend on your application) : </p> <pre><code>$scope.updateData=function(){ $timeout(function(){ //$http.get('/your/url').success(...).error(...) //you should get your data here, but I just force it for the example $scope.rawData=[{"time":n.getTime(),"content":"The value created when the page loaded"}, {"time":onemin,"content":"The value was created one minute before the page load"}, {"time":twomin,"content":"The value was created two minute before the page load"}]; console.log($scope.rawData) var whatTimeIsIt=new Date(); $scope.data=Array()//erasing any previous data $scope.notShown=Array();//for the test for(var i in $scope.rawData){ if($scope.rawData[i].time&gt;(whatTimeIsIt.getTime() - 90*1000))//checking each value time, if there was more than 1 min 30 sec or not { $scope.data.push($scope.rawData[i]); } else { $scope.notShown.push($scope.rawData[i]) } } //at the end of the function, we populated $scope.data with all the object with a time less than 1min 30 ago $scope.updateData();//schedule the next update } ,1000); } $scope.updateData(); </code></pre> <p>The code is just for this precise example, so you will have to adapt it, but the concept works. On the HTML side, you can, of course, show the values, which I did in two parts for the example, the data which should be shown ( within the time limit ) and the data which would have been skipped ( > time limit )</p> <pre><code> Values that should be shown : &lt;div ng-repeat='values in data'&gt; {{values.time}} : {{values.content}} &lt;/div&gt; &lt;br/&gt; Values outdated : &lt;div ng-repeat='values in notShown'&gt; {{values.time}} : {{values.content}} &lt;/div&gt; </code></pre> <p>If you watch the console, you can see every call to the function, every second. </p> <p>In this example I set 1min30 for the time limit, so the 2 first objects will be on the displayed list for 30 second, the 31 seconds later, only the first will be shown for another 1 minute, and then all of them should be hidden/deleted/sent to mordor/whatever you want</p> <p>Hope this helps, good luck</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload