Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript angularjs如何使方法在控制器中调用自身_Javascript_Jquery_Angularjs_Frontend - Fatal编程技术网

Javascript angularjs如何使方法在控制器中调用自身

Javascript angularjs如何使方法在控制器中调用自身,javascript,jquery,angularjs,frontend,Javascript,Jquery,Angularjs,Frontend,所以,我的问题是,如何使控制器方法调用自身(其在控制器构造函数中定义),例如: this.getExportPath = function() { setTimeout(function() { console.log(1); return getExportPath(); }, 1); } 我试过: this.getExportPath(); getExportPath(); return getExportPath(); return thi

所以,我的问题是,如何使控制器方法调用自身(其在控制器构造函数中定义),例如:

this.getExportPath = function() {
    setTimeout(function() {
        console.log(1);
        return getExportPath();
    }, 1);
}
我试过:

this.getExportPath();
getExportPath();
return getExportPath();
return this.getExportPath();

请提供帮助。

您的问题是
不是当前对象。通常,您希望在控制器开始时将
self
分配给
this
,并使用self而不是this

所以


您的问题是,
不是当前对象。通常,您希望在控制器开始时将
self
分配给
this
,并使用self而不是this

所以


var getExportPath=function(){..}
then
getExportPath()。?但是我不能在construcotr之外调用函数。你是说你想对函数进行递归调用吗?你可以使用
$interval
var getExportPath=function(){..}
然后
getExportPath()。?但是我不能在construcotr之外调用函数。你的意思是要对函数进行递归调用吗?你可以使用
$interval
。。
var self = this;
self.getExportPath = function(){
    setTimeout(function(){
        self.getExportPath();
    },1)
}