javascript - Access previous element item in angularjs filter -


when creating filter in angularjs how access previous item in array? i.e want compare current element previous one

hard figure out you're trying achieve, think if you're using ng-repeat can this:

html:

<div data-ng-repeat="element in elements">     <div>{{ element | myfilter:elements:$index</div> </div> 

javascript

.filter("myfilter", function(){     return function(input, elements, index){          if(index > 0){             var previouselement = elements[index - 1]         }          return input;     } }); 

edit

ok you've specified you're trying do, can use filter in different way instead remove duplicate dates.

here's filter:

.filter("uniquedates", function(){     return function(input){       var returninput = [];         for(var x = 0; x < input.length; x++){             if(returninput.indexof(input[x]) === -1){                 returninput.push(input[x]);             }         }        return returninput;       }; }) 

here's jsfiddle html , wired can extrapolate from: http://jsfiddle.net/ne9ee/


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -