I had been reading up on AngularJS Factory and Services and came across a lot of examples. But I'm not understanding the logic behind them and can't get them to work either.
myApp.service('loginCheck', function(Facebook) {
this.loggedIn = false;
Facebook.login(function(response) {
if (response.status == 'connected') {
this.loggedIn = true;
}
});
});
I need to get this service to return the loggedIn variable, if my idea of the concept is right. Should I use a factory instead? I need to store this variable all along, without making the call again every once I need it. How can I do it. I couldn't really understand the difference between factory and service. I'm a beginner here.
if(loginCheck.loggedIn){
console.log("logged in!");
}
else{
console.log("not logged in :/")
}
Thank you.