angularjs - angular filter on click by 'last week' data -


hi new in angular , making first module. article helpfull. want filter data lastweek records. have found days current date , given date in mysql query, on button click setting value distopic=1 , works fine.

may please tell me how can apply filter range day>=1 && day<=7

i using below:-

filter:{'topic': distopic,'attachment':attch, 'days':day} 

please me.

solution 1: angular-filter module

as stated other users, indeed custom filter. however, if find writing lot of custom filters, i'll advise have @ angular-filter module. module can need pick filter :

<div ng-repeat="task in tasks | pick: 'days >= 1 && days <= 7'">{{task.name}}</div> 

see demo fiddle


solution 2: custom filter parameters

template:

<div ng-repeat="task in tasks | dayfilter: 1 : 7">{{task.name}}</div> 

javascript:

app.filter('dayfilter', function() {     return function(input, startday, endday) {         var filterfunction = function (item) {             return item.days >= startday && item.days <= endday;         };         return input.filter(filterfunction);     }; }); 

see updated demo fiddle


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -