I have a quiz and want to randomize the data coming from my jSON file so that every time someone attempt the quiz sees different question order.
I came across this example but couldn't make it work out with the array comming from my jSON file. See the JS bellow:
.controller('QuizController', ['$scope', '$http', function($scope, $http, $state){
$scope.score = 0;
$scope.activeQuestion = -1;
$scope.activeQuestionAnswered = 0;
$scope.percentage= 0;
$http.get('js/quiz_data.json').then(function(quizData){
$scope.myQuestions = quizData.data;
$scope.totalQuestions = $scope.myQuestions.length;
});
$scope.randomSort = function(myQuestion) {
return Math.random();
};
HTML:
ng-repeat="myQuestion in myQuestions|orderBy:randomSort">
It would be nice if the answers were in random order also... Thanks in advance!