J'essaye de faire un filtre qui montrera juste des entrées de json pour un certain mois, janvier. Cependant, j'ai des problèmes. J'ai essayé de définir des variables pour Jan et Feb, puis de définir l'entrée à être supérieure à la première date de Jan et inférieure à la première date de février, mais cela n'a pas fonctionné. Toute aide serait grandement appréciée.angular.js filtrez par mois
Voici mon html:
<div ng-app="myApp" ng-controller="Catalog">
<div class="bg" ng-repeat="book in books">
<div ng-show=" book.doc.date | mydate" >
<div class="date">{{book.doc.date}}</div>
<div class="title">{{book.doc.title}}</div>
<div class="quote">{{book.doc.quote}}</div>
<div class="attribution">-{{book.doc.attribution}}</div>
<div class="textt">{{book.doc.text}}</div>
<div style="height:10px"></div>
</div>
</div>
<div class="bg" ng-repeat="book in books ">
<div ng-click="showInfo = !showInfo" ng-show=" book.doc.date | January">
<div class="date">{{book.doc.date}}</div>
<div class="title">{{book.doc.title}}</div>
<div class="quote" ng-show="showInfo">{{book.doc.quote}}</div>
<div class="attribution" ng-show="showInfo">- {{book.doc.attribution}}</div>
<div class="textt" ng-show="showInfo">{{book.doc.text}} </div>
<div style="height:10px"></div>
</div>
</div>
</div>
et mes JS:
var myApplication = angular.module('myApp', ['ngColorThis']);
myApplication.controller("Catalog", function ($scope) {
$scope.books = books;
$scope.showInfo = false;
})
.filter('mydate', function() {
return function(input) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0, so always add + 1
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
today = mm + '/' + dd;
return (input == today)
}
})
.filter('past', function() {
return function(input) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0, so always add + 1
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
today = mm + '/' + dd;
return (input)
}
})
.filter('January', function() {
return function(input) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0, so always add + 1
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
today = mm + '/' + dd;
var jan = 00 + "/" +00;
var feb = 01 + "/" + 00;
return (input > jan && input < feb)
}
});
est également ici une plunker complète de mon projet.