I have this factory:
app.factory('user', function($http) {
var state; // logged state
function login(data) {
$http.post('/login', {..}).success(function(data) {
this.state = 1;
});
console.log(this.state); // undefined
return this.state;
}
return {
login: login
}
});
When I try to use it inside a controller:
app.controller('TestCtrl', function(user) {
this.login = function() {
alert(user.login(this.data)); // undefined
};
});
What am I doing wrong? I've got same code in other project and it's working there.