Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An example showing the use of angular $q promises to authenticate a Firebase session and then writing data.
<html ng-app="test">
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<body ng-controller="Test">
<script typ="text/javascript">
function TestController($scope, $q) {
this._q = $q;
this._scope = $scope;
this.auth_token = "tAN8DtyE5BQshfbEK4mOMBEAnt3RLjjIIFl565Fe";
TestController.prototype = {
ref: function(path) {
var self = this;
var deferred = this._q.defer();
var ref = new Firebase("" + path);
ref.auth(self.auth_token, function(err) {
if (!err) {
console.log("Login succeeded");
} else {
console.log("Login failed " + err);
return deferred.promise;
set: function(ref, data) {
ref.set(data, function() {
console.log("Set completed!");
angular.module("test", []).controller("Test", function($scope, $q) {
var ct = new TestController($scope, $q);
var promise = ct.ref("/data");
promise.then(function(ref) {
ct.set(ref, "Hello World!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.