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
Post a Comment