I am currently working on developing a custom filter to showcase the most recent file in my system using AngularJS for data filtering.
The challenge I am facing is that the date information is saved as a string in my json file, and I'm unsure how to filter it appropriately.
My approach involves creating a custom filter by defining today's date as a variable and comparing it with the date stored in the json file.
Below is a snippet of my json file structure:
{
"data": [
{
"title": "Something Exciting",
"description": "A TV show about something really exciting.",
"date": " 06/2017",
"link": "../pdf/whoReadsBooksAnyway.pdf"
},
{
"title":"Stranger Things",
"description":"Getting back that 80's Steven King Vibe",
"date": "05/2017",
"link": "../pdf/AllAlongTheWatchTower.pdf"
}
]
}
I aim to display items based on the latest date
field, hence the creation of a custom filter:
app.filter('dateFilter', function($scope){
$scope.getDatetime = new Date();
var aaa = "../../../views/TvShows/json/shows.json"
$http.get(aaa).then(function maybe(response, date){
$scope.data = reseponse.data.data;
});
if($scope.getDatetime < $scope.data.date){
return $scope.myFilter;
} else{
console.log("it didn't work");
}
});
The filter is designed to fetch the date through an http request and compare it to $scope.GetDatetime
which represents the current date. I'm still figuring out the filter implementation.
xstatsx
is a $scope
object obtained from the initial http get request.
var xurlx = '../../../views/TvShows/json/shows.json'
$http.get(xurlx).then(function(response, data){
$scope.xstatsx = response.data.data;
});
To filter and display only the most recent date in my HTML, I use the following:
<div class="well well-lg" style="display: inline-block;" ng-repeat="n in xstatsx | orderBy: '-date'" ng-show='0 == $index'>
Any suggestions on how I can effectively filter and display only the latest updated files?