[英]How to call function in AngularJS controller with $scope method?
[英]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.