I'm probably making a beginners mistake. I'm trying to figure out how to access a function or variable in the this context of a service, while within the then() portion of a promise.
Here's some example code:
ndtApp.service("userService", ['$http',
function($http){
this.saveLoginInfo = function(data){
//do some stuff here.
}
this.login = function(){
//Login
$http.get('http://example.com/userlogin').then(
function(data){
this.saveLoginInfo(data);
//This won't work because 'this' from here is 'window' rather than the service.
},
function(data){
//error handling
});
}
}]);
How do I reach the saveLoginInfo function?
thisfor this very reason.