I am working on a quiz app. I have been trying to figure out how I can shuffle the options in a quiz question.
I have researched all over, the closest I found was this: shuffle array in ng-repeat angular
However, I was unsuccessful in implementing the shuffleArray() function. It wouldn't work for me.
I have created a jsfiddle http://jsfiddle.net/fa4v8/121/
This is my ng-repeat:
<div ng-controller="MyCtrl">
<p ng-repeat="(key,i) in options">{{options[key].text}}</p>
</div>
and this is my controller:
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.options = {
"d": {
"text": "Answer1-d"
},
"c": {
"text": "Answer1-c"
},
"a": {
"text": "Answer1-a"
},
"b": {
"text": "Answer1-b"
}
}
}
the output keeps coming in this order: (a,b,c,d)
Answer-a
Answer-b
Answer-c
Answer-d
Is there a way to make the options displayed in the order as the $scope.options (d,c,a,b) or display them in random order?