Created
May 4, 2014 14:32
-
-
Save NoelLH/4c1e79b8c24cb90757a1 to your computer and use it in GitHub Desktop.
Sample files for Phonegap + AngularJS + Facebook walkthrough at http://noellh.com/blog/phonegap-angularjs-facebook/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('demoapp', ['ngRoute', 'demoapp.services', 'demoapp.controllers', 'ezfb']) | |
.config(function (ezfbProvider) { | |
ezfbProvider.setInitParams({ | |
appId: '12345', | |
nativeInterface: CDV.FB, | |
useCachedDialogs: false | |
}); | |
ezfbProvider.setLoadSDKFunction(function ($rootScope, ezfbAsyncInit) { | |
$rootScope.ezfbAsyncInit = ezfbAsyncInit; | |
}); | |
}) | |
.config(function ($routeProvider) { | |
$routeProvider | |
.when('/', { | |
controller: 'MainCtrl', | |
templateUrl: 'partials/main.html' | |
}) | |
.when('/view', { | |
controller: 'ViewCtrl', | |
templateUrl: 'partials/view.html' | |
}) | |
.otherwise({redirectTo: '/'}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('demoapp.controllers', ['ezfb']) | |
.controller('MainCtrl', ['$scope', 'ezfb', function ($scope, ezfb) { | |
$scope.status = "It works!"; | |
$scope.init = false; | |
updateLoginStatus(); | |
$scope.login = function () { | |
ezfb.login(function (res) { | |
if(res.status == 'connected') { | |
updateLoginStatus(updateMe); | |
} | |
}, {scope: 'email'}); | |
}; | |
$scope.logout = function () { | |
ezfb.logout(function () { | |
updateLoginStatus(updateMe); | |
}); | |
}; | |
$scope.me = function() { | |
updateMe(); | |
}; | |
function updateMe() { | |
ezfb.api('/me', function(response) { | |
$scope.user = response; | |
}); | |
} | |
function updateLoginStatus() { | |
ezfb.getLoginStatus(function (res) { | |
$scope.loginStatus = res; | |
if(res.status == 'connected') { | |
updateMe(); | |
} | |
}); | |
} | |
}]) | |
.controller('ViewCtrl', ['$scope', function ($scope) { | |
$scope.status = "Also totally works!"; | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2> Main View: {{ status }} </h2> | |
<div ng-show="!init"> | |
<button ng-click="ezfbAsyncInit(); init = true;">FB Initialize</button> | |
</div> | |
<div ng-show="init"> | |
<button ng-click="login()">Connect with Facebook</button> | |
<button ng-click="me()" ng-show="loginStatus.status == 'connected'">Update me!</button> | |
<button ng-click="logout()" ng-disabled="!init || !loginStatus || loginStatus.status != 'connected'">Logout</button> | |
</div> | |
<ul> | |
<li>Hi {{ user.name }}!</li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment