0
我一直在尝试在AngularJS中使用Facebook登录API。但我无法更新变量。AngularJS中的全局变量未更新
$scope.init = function() {
$scope.name = ""
window.fbAsyncInit = function (response) {
FB.init({
appId: 'xxxxxxxxxxxxxxxxxxx',
xfbml: true,
version: 'v2.7'
});
FB.getLoginStatus(function (response) {
if (response.authResponse) {
//Calling Fb graph api if user is log in and fetching name of user
FB.api('/me', {
fields: 'name'
}, function (response) {
$scope.name = response.name;
console.log($scope.name); // 1
});
console.log($scope.name); // 2
}
});
};
console.log($scope.name); // 3
}
第一console.log()
表示$scope.name
正确的数据,即,仅在FB.api
。但其他人不显示更新的价值。
首先,是否有理由在第3行末尾没有分号?其次,冒着验证显而易见的风险...你是否检查控制台以确保调用FB.api不会导致错误? – dat
可能的重复[如何返回来自异步调用的响应?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – JLRishe