Whenever I look at my code below, I am able to successfully add a project and link it with the user. However, whenever I try to retrieve a user's projects, I keep encountering this error:
TypeError: undefined is not a function
I have also attempted to use $child at the top, but that approach doesn't seem to be working either. Here is my code:
'use strict';
angular.module('writer')
.factory('Users', ['firebaseURI', '$firebase', 'Auth', function(firebaseURI, $firebase, Auth){
var currentUser = Auth.currentUser,
users = new Firebase(firebaseURI + 'users');
function _getProjectsForCurrentUser(){
return users.child(currentUser.id + '/projects/');
}
function _addProjectForCurrentUser(projectRef){
users.child(currentUser.id + '/projects/' + projectRef.key()).set(true);
}
return {
getProjectsForCurrentUser: _getProjectsForCurrentUser,
addProjectForCurrentUser: _addProjectForCurrentUser
};
}])
.factory('Projects', ['firebaseURI', '$firebase', 'Auth', 'Users', function(firebaseURI, $firebase,
Auth, Users){
var projectsRef = new Firebase(firebaseURI + 'projects'),
projects = $firebase(projectsRef);
function _getProjects(){
return projects;
}
function _create(project){
console.log('create', project);
projects.$push(project).then(function(ref){
Users.addProjectForCurrentUser(ref);
}, function(error){
console.log('Projects Error:', error);
});
}
return {
getProjects: _getProjects,
create: _create
};
}])
;
If anyone could provide assistance, it would be greatly appreciated.