I am trying to figure out a way to list the "latest upcoming events" using AngularJS consuming a JSON feed.
I want to grab today's current date (using either server or client side?) and then iterate through a JSON list and only print/filter the latest 2 upcoming events based on today's current date.***
Here's how I have my controller set up:
var app = angular.module('listApp', []);
app.controller('Ctrl', function($scope){
$scope.events = [
{
"title": "All Day Event",
"start": "2015-07-11"
},
{
"title": "Long Event",
"start": "2015-07-07"
},
{
"title": "Repeating Event",
"start": "2015-07-16"
},
{
"title": "Repeating Event",
"start": "2015-07-10"
}
]
});
Here's my view:
<body ng-app="listApp">
<div class="container" ng-controller="Ctrl">
<h3>Upcoming events:</h3>
<ul ng-repeat="event in events | limitTo: 2">
<li>{{ event.title }}</li>
<li>{{ event.start }}</li>
</ul>
</div><!--/.container-->
I think I need to write a conditional statement in the controller utilizing the Date.now(), but I am unsure how to get started. Perhaps I am on the wrong path and someone else has a better approach?