I have this Directive:
.directive('reorderDiv', function ($compile) {
return function (scope, elem, attrs) {
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// Elemente
while (0 !== currentIndex) {
// Die restlichen Elemente
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
elem.on('click', function () {
console.log('called');
var divs = angular.element(document.querySelector('.center'));
console.log(divs);
divs = shuffle(divs);
var content = $compile(divs)(scope);
elem.append(content);
})
}
})
My goal is, that if the view loads it should run the function shuffle and not on a click on the element. How can i do this?
I tried to use elem.on("load")[...] but this didn't work. Could somebody explain me, why this does not work?
clickevent..