I have an ng-repeat as following :
<ul>
<li ng-repeat="o in villes | limitTo:5"><a href="#">{{o.nomVille}}</a></li>
</ul>
I want to reorder the villes
list randomly before I limit it to 5
, so every time I open my page I get 5 different villes
each time.
is there a filter in angularjs who can do that for me ?
edit :
I created a costum filter to randomize that list as following :
.filter('random', function() {
return function(val) {
let shuffle = (a) => {
let r = [];
while (arr.length)
r.push(
arr.splice( (Math.floor(Math.random() * arr.length)) , 1)[0]
);
return shuffle(val);
}
};
});
and in ng-repeat I did this :
<li ng-repeat="o in villes | random | limitTo:5"><a href="#">{{o.nomVille}}</a></li>
but I cant no longer see anything in my page.
this is the example on jsfiddle : https://jsfiddle.net/z10wwhcv/