I'm trying to modify a variable inside a function, but there must be something with the scope that I'm not understanding, code:
app.factory("UserService", function(){
var foo = 'bar';
return {
init: function(){
var self = this;
self.create();
},
create: function(){
$.post(server+"api/users", {
uuid: self.uuid
})
.done(function(data) {
if(data.reply !== 0){
foo = true;
} else {
foo = false;
}
});
return foo;
}
};
});
Why can't I change the value of foo from within the functions? I've tried doing this.foo, self.foo, after assigning this to self, among so many other things, and I believe I'm missing something way too obvious and I'll feel like an idiot after someone clears it up for me.
Thanks.