filtering current date into a arraylist with AngularJS

376 views
Skip to first unread message

Luis Ruiz Figueroa

unread,
Nov 16, 2014, 8:57:50 PM11/16/14
to ang...@googlegroups.com

I'm building a filter AngularJS, to display only data that contains the current date in the query, at the moment I'm doing this, but I can not get it to work.

-J_Wjq2vkPJxCkmk3Wxp
  Estado: "pendiente"
  FechaActividad: "2014-11-11"
  NombreActividad: "Actividad 1"

  -J_WrCwULkPGRD5-mZ6z
  Estado: "aprobado"
  FechaActividad: "2014-10-11"
  NombreActividad: "Actividad 2"

This is the filter I try to build to build

 app.filter('fechas', function($filter)
{
 return function(input)
 {
  if(input == null){ return ""; }

  var _date = $filter('date')(new Date(input), 'MMM dd yyyy');

  return _date.toUpperCase();

 };
});

and so I am showing my html.

 <div ng-repeat="i in list | date">
<span>{{i.Estado}}</span>
<span>{{i.FechaActividad}}</span>
<span>{{i.NombreActividad}}</span>
</div>

also try to do the following but neither had resulted

 <div ng-repeat="i in list | fechas:['FechaActividad']">

Vivek Anand

unread,
Nov 17, 2014, 1:11:30 PM11/17/14
to ang...@googlegroups.com
Filter, which you tried to build will not serve the purpose.

In this case, your filter must return a boolean, which will select the record in ng-repeat to be displayed.

Solution to your problem can be addressed in the following way:

1. Create a variable dt in $scope within controller as:
$scope.dt = $filter('date')(new Date(), 'yyyy-MM-dd');

2. Change the HTML fragment as:
<div ng-repeat="i in data | filter: {FechaActividad: dt}">
    <span>{{i.Estado}}</span><br/>
<span>{{i.FechaActividad}}</span><br/>
<span>{{i.NombreActividad}}</span><br/>
<hr/>
</div>

Hope this resolves the problem.

Luis Ruiz Figueroa

unread,
Nov 17, 2014, 2:05:00 PM11/17/14
to ang...@googlegroups.com
excellent, I fix, was grateful. regards

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/qj6PdqnmsWQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--

 
Logo

​Luis Ruiz F.
​Administración - Web Master
81801756 · luisruiz...@gmail.com 

Tu Chillan

  facebook twitter    Google+  

Luis Ruiz Figueroa

unread,
Nov 17, 2014, 2:05:37 PM11/17/14
to ang...@googlegroups.com
excellent, I fix, was grateful. regards

Reply all
Reply to author
Forward
0 new messages