I have defined a factory in AngularJS similar to the following:
angular.module("myApp").factory(function (){
var userObject = {
userID: '',
email: '',
};
userObject.isLoggedIn = function(){
if(userObject.email === '')
retu false;
else
retu true;
};
//more code goes here for the factory
//...
retu userObject;
}
The problem is, every time I call the isLoggedIn() function from my controllers, it retus a false. I tried if (this.userObject.email === ''), which retus the error TypeError: Caot read property 'token' of undefined in the console.
This functionality works fine when I define userObject in a service. Is there some scope limitation that I'm missing? What am I doing wrong?
