Angularjs 无延迟角度超时调用函数

Angularjs 无延迟角度超时调用函数,angularjs,Angularjs,在下面的代码段中,进程调用将被连续触发,但没有10秒的延迟。请告诉我哪里出了问题 ctrl.progress =function (fileName){ if(ctrl.status < 100){ ctrl.timer = $timeout(function(fileName){ LookUpValueService.getImportStatus(fileName).

在下面的代码段中,进程调用将被连续触发,但没有10秒的延迟。请告诉我哪里出了问题

        ctrl.progress =function (fileName){

            if(ctrl.status < 100){
                ctrl.timer = $timeout(function(fileName){

                    LookUpValueService.getImportStatus(fileName).
                    then(function(value){
                        ctrl.status = value; 
                        ctrl.progress(fileName);
                    });
                    //ctrl.status = ctrl.status + 1;                

                }(fileName),5000);
            }
            else{
                $timeout.cancel(ctrl.timer);
            }
        }; ctrl.progress("test.txt");
ctrl.progress=函数(文件名){
如果(ctrl.status<100){
ctrl.timer=$timeout(函数(文件名){
LookUpValueService.getImportStatus(文件名)。
然后(函数(值){
ctrl.status=值;
ctrl.progress(文件名);
});
//ctrl.status=ctrl.status+1;
}(文件名),5000);
}
否则{
$timeout.cancel(ctrl.timer);
}
}; ctrl.progress(“test.txt”);

函数的第一个参数必须是函数本身,而不是函数调用的结果

在您的情况下,
ctrl.progress()
不返回函数,它返回未定义的函数,因此当您有:

ctrl.timer = $timeout(ctrl.progress(fileName), 10000);
发生的情况是,
ctrl.progress(fileName)
立即被调用,返回undefined,然后告诉
$timeout()
在执行
undefined
之前等待10秒

将该行更改为使用函数,它将工作:

ctrl.timer = $timeout(() => ctrl.progress(fileName), 10000);

(或者如果不使用ES6/2015/TypeScript:
ctrl.timer=$timeout(函数(){ctrl.progress(fileName)},10000);

感谢您的快速响应。将代码更改为原始帖子中建议的代码,仍然面临相同的问题:(@maheshreddy答案是正确的。您正在做与以前相同的事情。不应使用
(文件名)调用该函数
。您使用的是IIFE,而不是$timeout callback,它代表立即调用的函数表达式。啊,谢谢,我尝试了不同的方法,并使其成为IIFE。删除IIFE解决了问题,谢谢!!