mardi 25 avril 2017

Shuffle ng-repeat results

I have some data in Firebase and I'm puting it on my website and filter them. I want to show just 4 random items with property "cheap: true". Unfortunetaly I don't have any idea how can I shuffle this output. I created random function, but it causes an error:

[$rootScope:infdig]

I'd be very grateful if you could help me with shuffling these 4 results. Here is my code:

HTML:

<div ng-repeat="place in places | filter: {cheap: 'true'} | limitTo: 4 | orderBy: random" class="col-lg-3">

JS:

// Random order by
    $scope.random = function() {
      return 0.5 - Math.random();  
    };

And my Firebase data is here:

// Firebase
    $scope.places = $firebaseArray(ref);




Aucun commentaire:

Enregistrer un commentaire