I want to be able to call a function inside the .then scope, and for that I use the this.foo() manner. But if I do this inside the .then I get an error, since this appears to be lost. What can I do?
In this code, this would be equivalent to have the same output for the object this
console.log(this)
one().then(function() {
console.log(this)
})
function one() {
var deferred = $q.defer();
deferred.resolve()
return deferred.promise;
}
This neither seems to work
console.log(this)
var a = this;
one().then(function(a) {
console.log(a)
})