繁体   English   中英

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)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM