具有延迟的角度函数

时间:2013-12-15 22:50:53

标签: javascript angularjs

您希望在延迟5秒后执行applyParameters功能。但是我当前的语法没有这样做。

有关如何做到这一点的想法吗?

//Add and update categories
                var categories = homeData['categories'];
                for(var catIndex in categories){
                    var category = categories[catIndex];
                    $scope.addCategory(category);
                }

                $scope.search.text = homeData['keyword'];

                //Pick first company in the results
                $scope.updateSelectedCompany( response.data[0] );

                //populate parameters if passed in after 1 second delay
                $timeout($scope.applyParameters($routeParams.param1), 5000);

1 个答案:

答案 0 :(得分:2)

将代码包装在函数中:

$timeout(function(){
     $scope.applyParameters($routeParams.param1);
}, 5000);

目前评估$scope.applyParameters($routeParams.param1),Angular会尝试将applyParameters的返回值作为函数调用。