Node.js Express.js+;脸谱网
我在尝试使用此Express应用程序时遇到问题。我想在Facebook getLoginStatus函数中调用(response.status==='connected')if分支中的一个函数。代码如下:Node.js Express.js+;脸谱网,node.js,facebook,express,Node.js,Facebook,Express,我在尝试使用此Express应用程序时遇到问题。我想在Facebook getLoginStatus函数中调用(response.status==='connected')if分支中的一个函数。代码如下: (function(){ var app = angular.module('AppProva', ['ngResource']); app.controller('friendFetcherCtrl', ['$window', function($window
(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'));
};
}]);
})();
login函数由div中的ng init指令调用。
加载HTML页面时,我会收到错误“TypeError:this.getFriends不是函数”。可能问题是我在$window中定义的函数中调用了这个.getFriends()。我怎样才能让事情运转起来
提前谢谢大家,,
弗朗西斯科
编辑:我想我知道问题在于“this”关键字,但我如何才能让它在没有它的情况下工作?这很简单。在
FB.getLoginStatus
中,这个
指向其他东西。解决办法:
(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 will point to this in app.controller's function
/*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'));
};
}]);
})();
可能是魔兽世界的复制品,这真的很简单!谢谢你,伙计,现在它工作正常了!