Im unable to get fb name printed using angular js. I’m not sure what is going wrong. In the below code, “no_name” gets printed. JSON alert show correctly.
I have this view code trying to print l from the scope
<div ng-controller="TestCtrl">
{{n}}
</div>
This is the controller code:
function TestCtrl($scope){
$scope.n="no_name";// default value
FB.login(function(response) {// fb login as soon as the ui loads
if (response.authResponse) {
FB.api('/me', function(response) {
alert(JSON.stringify(response));
$scope.n=response.name;
});
} else {
//do nothing..
}
});
}
I assume, FB is some external module, that is not aware about AngularJS and its event cycle (or call
$scope.$apply()which I consider is not so descriptive)In this case you should wrap callbacks, that change your scope with
$apply: