javascript - AngularJS - Asynchronous call to Facebook API -
i'am trying call facebook api angularjs.
the problem calls fb api asynchronous, need know when query on facebook avaliable use in agularjs.
for this, call method in controller:
facebook.getloginstatus();
which facebook service, defined as:
app.factory('facebook', function() {
getloginstatus: function() { fb.getloginstatus(function(stsresp) { console.log(stsresp); if(stsresp.authresponse) { // user logged in return true; } else { // user not logged in. return false; } }); }
}
what want in case check if user logged. if true, i'll show options, otherwise, i'll show login button.
i've try use $q.defer() functions, promises, factorys watch response data, everything. works want. i've checked development examples based on egghead.io examples, think i'm not understand asynchronous calls in angularjs.
thanks in advance.
here's full basic working example of wrapping facebook api in angular service:
http://plnkr.co/edit/0grldwpjozgfy14irxlt?p=preview
see answer question (which has partial examples of angular-fb integration):
Comments
Post a Comment