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