Skip to content

@NoelLH /app.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Sample files for Phonegap + AngularJS + Facebook walkthrough at http://noellh.com/blog/phonegap-angularjs-facebook/
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: '/'});
});
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!";
}]);
<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
Something went wrong with that request. Please try again.