Book Image

AngularJS Web Application Development Blueprints

By : Vinci J Rufus
Book Image

AngularJS Web Application Development Blueprints

By: Vinci J Rufus

Overview of this book

Table of Contents (17 chapters)
AngularJS Web Application Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting the user's friend list


Now that we know how to make requests to the Facebook API and get it to update correctly in our views, let's now see how to get the list of friends of the logged-in user.

We will create our function named loadFriends and call it within the controller option of the myFriends directive, as shown in the following code snippet:

      controller: function($scope) {
        $scope.loadFriends = function() {

          FB.api('/me/friends', function(response) {
            $scope.$apply(function() {
              $scope.myFriends = response.data;
              console.log($scope.myFriends);
            });

          });
        };
      }

As you can see, the $scope.loadFriends function loads the FB.api method, making a request to the me/friends end point.

The response from the request is stored in the $scope.myFriends scope object. Note that we have to manually wrap it within the $apply function, because the FB.api call is external to the angular-context.

We'll now need...