I'm experiencing problems trying to get this Express app working. I want to call a function in the (response.status === 'connected') if branch, inside the Facebook getLoginStatus function. Here's the 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() { /* Do something */ }, { 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 is called by the ng-init directive inside a div. When load my HTML page I get the error "TypeError: this.getFriends is not a function". Maybe the problem is that I call this.getFriends() inside a function define in $window. How can I get things working?
Thank you in advance, Francesco
EDIT: I think I know the probles is the "this" keyword but how can I make it work without?