'use strict';

angular.module('ngSocial.facebook', ['ngRoute','ngFacebook'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/facebook', {
    templateUrl: 'facebook/facebook.html',
    controller: 'FacebookCtrl'
  });
}])

.config( function( $facebookProvider ) {
  $facebookProvider.setAppId('450853485276464');
  $facebookProvider.setPermissions("email","public_profile","user_posts","publish_actions","user_photos");  
})   

.run( function( $rootScope ) {
     (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
})


.controller('FacebookCtrl', ['$scope', '$facebook', function($scope,$facebook) {

    $scope.isLoggedIn = false;
    $scope.login = function(){
        $facebook.login().then(function(){
           $scope.isLoggedIn = true;
           refresh();
        });
    }

    $scope.logout = function(){
        $facebook.logout().then(function(){
           $scope.isLoggedIn = false;
           refresh();
        });
    }
   
    function refresh(){
        $facebook
            .api('/me')
            .then(function(response){
            $scope.welcomeMsg = 'Welcome '+response.name;
            $scope.isLoggedIn = true;
            $scope.userInfo = response;
            console.log('Change is: ');
            console.log( $scope.userInfo);
        },function(error){
            $scope.welcomeMsg = 'Please, log in';
        });
    }

     refresh();
}]);


/*


down vote
$facebookapi('/me?fields=first_name, last_name, picture, email', function(response) {
    $scope.welcomeMsg = 'Welcome '+response.name;
    $scope.isLoggedIn = true;
    console.log(response);
}, function(error){
    $scope.welcomeMsg = 'Please, log in';
});


        $facebook
            .api('/me?fields=id,name,email')
            .then(function(response){
            $scope.welcomeMsg = 'Welcome '+response.name;
            $scope.isLoggedIn = true;
            $scope.userInfo = response;
            console.log('Change is: ');
            console.log( $scope.userInfo);
        },function(error){
            $scope.welcomeMsg = 'Please, log in';
        });

*/
@@ -1207,20 +1207,17 @@
 ;%0A    %7D%0A
-   
 %0A
+
     func
@@ -1253,45 +1253,19 @@
 book
-%0A            
 .api(
-'/me')%0A            
+%22/me%22)
 .the
@@ -1426,48 +1426,8 @@
 se;%0A
-            console.log('Change is: ');%0A
     
@@ -1581,699 +1581,8 @@
 ();%0A
+
 %7D%5D);
-%0A%0A%0A/*%0A%0A%0Adown vote%0A$facebookapi('/me?fields=first_name, last_name, picture, email', function(response) %7B%0A    $scope.welcomeMsg = 'Welcome '+response.name;%0A    $scope.isLoggedIn = true;%0A    console.log(response);%0A%7D, function(error)%7B%0A    $scope.welcomeMsg = 'Please, log in';%0A%7D);%0A%0A%0A        $facebook%0A            .api('/me?fields=id,name,email')%0A            .then(function(response)%7B%0A            $scope.welcomeMsg = 'Welcome '+response.name;%0A            $scope.isLoggedIn = true;%0A            $scope.userInfo = response;%0A            console.log('Change is: ');%0A            console.log( $scope.userInfo);%0A        %7D,function(error)%7B%0A            $scope.welcomeMsg = 'Please, log in';%0A        %7D);%0A%0A*/

Fix 9: Add user details