Skip to content

Instantly share code, notes, and snippets.

@rotemtam
Created August 23, 2015 18:52
Show Gist options
  • Select an option

  • Save rotemtam/ffb2b9d59fb80ce58dc8 to your computer and use it in GitHub Desktop.

Select an option

Save rotemtam/ffb2b9d59fb80ce58dc8 to your computer and use it in GitHub Desktop.
angular.module('kahootCloneApp')
.controller('MainCtrl', function ($scope, $location, _, fbutil) {
$scope.newGame = function() {
$scope.creatingGame = true;
// Generate random 6 digit pincode for the game
var PIN = _.random(100000,999999),
// Connect to Firebase
game = fbutil.syncObject('games/' + PIN);
// Upon connection build game object
game.$loaded().then(function() {
game.data = {
'state' : 'waitingForPlayers',
}
return game.$save();
})
.then(function() {
// after save is completed take us to Host view
$location.path('/host/' + PIN);
})
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment