Reputation: 3832
Anyone know of a good way to randomize starting slide in the Angular version of Bootstrap Carousel component? I get my slides from a controller:
$scope.slides = [
{author: "Someone", content: "a content..."},
{author: "Sometwo", content: "another content"}
...
];
I'm thinking about randomize the ng-repeat output. But I actually dont need everything randomized, mostly just the starting slide... But if this is the best way, then fine!
Is there a way to pass some random start number to the carousel directive?
This doesn't have to be a "real" random function... a Math.random() will do just fine.
Got any good solutions?
Upvotes: 0
Views: 557
Reputation: 3832
Solved!
var shuffleArray = function(array) {
var m = array.length, t, i;
// While there remain elements to shuffle
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
shuffleArray($scope.slides);
Upvotes: 1