Last active
January 2, 2016 15:18
-
-
Save victorkurauchi/8322141 to your computer and use it in GitHub Desktop.
Angular Firebase Service
This file contains hidden or 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
// In this case it is a simple value service. | |
angular.module('myApp.services', ['firebase']). | |
value('version', '0.1') | |
// Serviço criado para persistir dados no firebase, | |
// com a possibilidade de ser a propria persistencia em base de dados como mongodb etc.. | |
.service('Firebase', function($rootScope, $firebase) { | |
return { | |
url: 'https://myurl.firebaseio.com', | |
path: '', | |
reference: null, | |
_construct: function(path) { | |
this.path = path; | |
var ref = new Firebase(this.url + '/' + path); | |
this.reference = $firebase(ref); | |
}, | |
on: function(eventName, callback) { | |
var _this = this; | |
_this.reference.$on(eventName, function () { | |
var args = arguments; | |
$rootScope.$apply(function () { | |
callback.apply(_this.reference, args); | |
}); | |
}); | |
}, | |
add: function(item) { | |
var _ref = this.reference; | |
_ref.push(item); | |
} | |
} | |
}); |
This file contains hidden or 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('myApp.services', []). | |
controller('FirebaseController', function ($scope, Firebase, $timeout) { | |
$scope.predicate = ''; | |
Firebase._construct('tarifas'); | |
Firebase.on('loaded', function(data) { | |
$timeout(function() { | |
console.log('waddup'); | |
console.log(data); | |
//$scope.messages.push(data.val()); | |
},0); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment