node.js - Express.js + Facebook -
i'm experiencing problems trying express app working. want call function in (response.status === 'connected') if branch, inside facebook getloginstatus function. here's code:
(function(){ var app = angular.module('appprova', ['ngresource']); app.controller('friendfetcherctrl', ['$window', function($window){ this.getfriends = function(){ console.log('getfriends()'); }; this.login = function() { console.log('login()'); $window.fbasyncinit = function() { fb.init({ appid: '****************', xfbml: true, version : 'v2.3' }); fb.getloginstatus(function(response) { if (response.status === 'connected') { console.log('logged in.'); this.getfriends(); /*facebook graph query*/ } else { fb.login(function() { /* */ }, { scope : 'user_friends, public_profile' }); } }); }; (function(d, s, id) { var js, fjs = d.getelementsbytagname(s)[0]; if (d.getelementbyid(id)) { return; } js = d.createelement(s); js.id = id; js.src = "//connect.facebook.net/en_us/sdk.js"; fjs.parentnode.insertbefore(js, fjs); }(document, 'script', 'facebook-jssdk')); }; }]); })();
the login function called ng-init directive inside div. when load html page error "typeerror: this.getfriends not function". maybe problem call this.getfriends() inside function define in $window. how can things working?
thank in advance, francesco
edit: think know probles "this" keyword how can make work without?
that's simple. inside fb.getloginstatus
, this
pointing else. work-around:
(function(){ var app = angular.module('appprova', ['ngresource']); app.controller('friendfetcherctrl', ['$window', function($window){ this.getfriends = function(){ console.log('getfriends()'); }; var self = this; this.login = function() { console.log('login()'); $window.fbasyncinit = function() { fb.init({ appid: '****************', xfbml: true, version : 'v2.3' }); fb.getloginstatus(function(response) { if (response.status === 'connected') { console.log('logged in.'); self.getfriends(); //self point in app.controller's function /*facebook graph query*/ } else { fb.login(function() { /* */ }, { scope : 'user_friends, public_profile' }); } }); }; (function(d, s, id) { var js, fjs = d.getelementsbytagname(s)[0]; if (d.getelementbyid(id)) { return; } js = d.createelement(s); js.id = id; js.src = "//connect.facebook.net/en_us/sdk.js"; fjs.parentnode.insertbefore(js, fjs); }(document, 'script', 'facebook-jssdk')); }; }]); })();
Comments
Post a Comment