Skip to content

Instantly share code, notes, and snippets.

@khannotations
Created July 19, 2016 11:56
Show Gist options
  • Select an option

  • Save khannotations/b99a0a186db1b0a6512131078cf3a3da to your computer and use it in GitHub Desktop.

Select an option

Save khannotations/b99a0a186db1b0a6512131078cf3a3da to your computer and use it in GitHub Desktop.
var app = angular.module("myApp", ["ngRoute", "firebase"]); // <-- angularfire
app.config(function($routeProvider) {
$routeProvider.when("/", {
controller: "HomeCtrl",
templateUrl: "/templates/home.html",
}).when("/signup", {
controller: "SignupCtrl",
templateUrl: "/templates/signup.html",
});
});
app.controller("SignupCtrl", function($scope, $firebaseAuth, $firebaseObject){
var auth = $firebaseAuth();
$scope.signUpWithEmail = function() {
// login with Facebook
auth.$createUserWithEmailAndPassword($scope.newUser.email, $scope.newUser.password)
.then(function(firebaseUser) {
// Set up connection to a particular point in my database
var userRef = firebase.database().ref().child("users").child(firebaseUser.uid);
// Load data from that place into my object
$scope.user = $firebaseObject(userRef);
$scope.user.name = firebaseUser.displayName;
// $scope.user.uid = firebaseUser.uid;
// $scope.user.created_at = Date.now;
$scope.user.email = firebaseUser.email;
console.log($scope.user);
$scope.user.$save();
console.log("Signed in as:", firebaseUser);
}).catch(function(error) {
console.log("Authentication failed:", error);
});
}
$scope.signInWithFacebook = function() {
// login with Facebook
auth.$signInWithPopup("facebook").then(function(firebaseUser) {
console.log("Signed in as:", firebaseUser.uid);
}).catch(function(error) {
console.log("Authentication failed:", error);
});
}
});
// Controller is the link between your HTML and
// your Javascript (data and functions)
app.controller("HomeCtrl", function($scope, $http){
// $http() returns Promise object.
// That object has a function called 'then'
var promise = $http({
url: "https://www.reddit.com/r/funny.json",
method: "GET",
params: {}
}).then(function(response) {
$scope.posts = response.data.data.children;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment