I have been trying to use the Facebook login API in AngularJS. But I am not able to update a variable.
$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
}
The first console.log()
shows the correct data in $scope.name
, i.e. only in FB.api
. But the others do not show the updated value.