IvRRimUm
IvRRimUm

Reputation: 1834

angularjs How to make method call itself in controller

So, my question, is how to make controller method call itself( its defined in controller constructor ), for example:

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

I have tryed:

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

Help would be appriciated.

Upvotes: 1

Views: 1410

Answers (1)

Dave Bush
Dave Bush

Reputation: 2402

Your issue is that this is not the current object. Typically, you want to assign self to this at the begginng of the controller and use self instead of this

So..

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

Upvotes: 4

Related Questions