AngularJS $scope 不适用于 Facebook SDK
AngularJS $scope not working for Facebook SDK
.controller('MainController',function($scope,$rootScope){
$scope.Name = "Loading"; // Working okay
$scope.Email = "Loading"; // Working okay
FB.getLoginStatus(function(response){
if(response.status === 'connected'){
FB.api('/me',{fields:'name,birthday,id,email'},function(response){
console.log(response.name); // Working okay
$scope.Name = response.name; // Not Working
$scope.Email = response.email; // Not Working
});
} else {
FB.login();
FB.ui({
method: 'pagetab',
redirect_uri: 'https://www.facebook.com/dialog/pagetab?app_id=376941409363083&redirect_uri=http://localhost'
}, function(response){});
}
});
});
这个范围给我带来了问题
我已经厌倦了这个问题,任何人帮助!
范围可能已更新,但 angular 并不知道,因为更新发生在 angular 的上下文之外(即不通过 $http 服务)。尝试将更新包装在 $apply
中
$scope.$apply(function(){
$scope.Name = response.name;
$scope.Email = response.email;
});
.controller('MainController',function($scope,$rootScope){
$scope.Name = "Loading"; // Working okay
$scope.Email = "Loading"; // Working okay
FB.getLoginStatus(function(response){
if(response.status === 'connected'){
FB.api('/me',{fields:'name,birthday,id,email'},function(response){
console.log(response.name); // Working okay
$scope.Name = response.name; // Not Working
$scope.Email = response.email; // Not Working
});
} else {
FB.login();
FB.ui({
method: 'pagetab',
redirect_uri: 'https://www.facebook.com/dialog/pagetab?app_id=376941409363083&redirect_uri=http://localhost'
}, function(response){});
}
});
});
这个范围给我带来了问题 我已经厌倦了这个问题,任何人帮助!
范围可能已更新,但 angular 并不知道,因为更新发生在 angular 的上下文之外(即不通过 $http 服务)。尝试将更新包装在 $apply
$scope.$apply(function(){
$scope.Name = response.name;
$scope.Email = response.email;
});