AngularJS $timeout循环只触发一次

AngularJS $timeout loop fires only once

本文关键字:一次 timeout 循环 AngularJS      更新时间:2023-09-26

我有以下内容,但是我要做的是每10秒让$timeout循环一次,但是下面正在做的是运行shuffleArray(),然后在10秒后再次触发它,就是这样。到此为止。

    $http.post("/content", {"Data":JSON.stringify($scope.content)}).success(function(data, status, header, config){
        $scope.ourcontent = data;
        shuffleArray($scope.ourcontent);
        $timeout(function() {
            shuffleArray($scope.ourcontent);
        }, 10000);
    });

你需要的是$interval,请看这里