I'm trying to use $timeout in Angular 1 to call a function every 2 seconds using ng-init.
ng-init="$timeout(sc.displaySorted(), 2000)"
The sc.displaySorted() function displays 100 sorted shapes on the DOM. It works fine with ng-init, but I'm struggling to get it to refresh every 2 seconds. I've also tried using $route.reload and recursion without success.
This is the vm.displaySorted function:
vm.displaySorted = function() {
// Call generateFunc and pass a total of 50 shapes
var allShapes = generateFunc(50);
// Call sortingFunc with all shapes as argument
var sortedShapes = sortingFunc(allShapes);
for(i = 0; i < sortedShapes.length; i++) {
var shape = sortedShapes[i]
if(shape.type === "square") {
vm.shapesToDisplay.push(sortedShapes[i]);
}
if(shape.type === "circle") {
vm.shapesToDisplay.push(sortedShapes[i]);
}
}
//end vm.displaySorted