Recently, I've been delving into AngularJS and I have a JSON file containing numerous objects that need to be displayed individually in separate partials. Out of the 100 objects in the JSON file, I'm looking to randomly select just three. How can I make this happen?
Here's a snippet from the controller:
myApp.controller('DetailsController', ['$scope', '$http','$routeParams' ,function($scope, $http, $routeParams) {
$http.get('js/JOSCO.json').success(function(data) {
$scope.questions = data; // Array of 100 objs
console.log($scope.questions);
$scope.whichItem = $routeParams.itemId; // Planning to assign 3 random numbers to whichItem
if($routeParams.itemId > 0){
$scope.prevItem = Number($routeParams.itemId) - 1;
}
else{
$scope.prevItem = $scope.questions.length - 1;
}
if($routeParams.itemId < $scope.questions.length-1){
$scope.nextItem = Number($routeParams.itemId) + 1;
}
else{
$scope.nextItem = 0;
}
});
}]);
At the moment, all 100 items are being selected...