Jeff answered the question correctly ... I just post further development on the example of Jeff for those who are interested.
I have distracted the creation of the Firebase service so that you can dynamically create an instance of any Firebase service you want: -
var registerFirebaseService = function (serviceName) { app.factory(serviceName, function (angularFire) { var _url = null; var _ref = null; return { init: function (url) { _url = url; _ref = new Firebase(_url); }, setToScope: function (scope, localScopeVarName) { angularFire(_ref, scope, localScopeVarName); } }; }); };
First create an instance of the service as follows
registerFirebaseService('itemsService');
You can then enter the itemsService into your controllers. An instance is initialized using a Firebase URL, for example.
itemsService.init('https://firebase.firebaseio.com/' + userId + '/items');
Now Firebase can be tied to your controller, for example.
itemsService.setToScope($scope, 'items');
adapted by PLUNKER
stukennedy
source share