我試圖讓這個Express應用程序工作時遇到問題。我想調用(response.status ==='connected')if分支中的函數,在Facebook getLoginStatus函數中。下面的代碼:Express.js + Facebook
(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'));
};
}]);
})();
登錄功能是通過DIV中的NG-初始化指令調用。 當加載我的HTML頁面時,我得到錯誤「TypeError:this.getFriends不是函數」。也許問題是我調用this.getFriends()函數在$ window中定義。我怎樣才能使事情發揮作用?
謝謝你在前進, 弗朗切斯科
編輯:我想我知道probles是「這個」關鍵字,但我怎樣才能使它工作沒有?
的可能重複[如何進行 「this」 關鍵字的工作?](http://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work) –