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

angularjs How to make method call itself in controller

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

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

我试过了:

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

我们会提供帮助。

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

所以..

var self = this;
self.getExportPath = function(){
    setTimeout(function(){
        self.getExportPath();
    },1)
}