0

I have a variable $scope.liking. It get's updated whenever somone clicks a like-button, that triggers the listener FB.Event.subscribe.

controller('LikeCtrl', ['$scope', '$window', function($scope, $window) {
  var page_like_callback = function(url, html_element) {
    $scope.liking = true;
    console.log($scope);
  };

  console.log($scope);
  FB.Event.subscribe('edge.create', page_like_callback);
}]);

In my template i have a <p>{{liking}}</p>

It won't update when FB.Event.subscribe fires. I can see with console.log that the scope is updated. Can I kick it to make the template upload or change the code somehow?

1 Answer 1

2

The callback is executed outside of the control of Angular. You need to explicitly evaluate the expression in the context of $scope. You can do so with $apply:

var page_like_callback = function(url, html_element) {
    $scope.$apply(function () {
        $scope.liking = true;
    });
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.