I'm developing a small chat using Firebase . My intention was to make login
in my application and save usuarioLogado
to the database and to make logoff
delete that user from the database.
Currently I can only save the user at the time of entering, at the time of deleting simply nothing happens, no error happens as well, the user just is not deleted.
Factory :
angular.module("UnionTi").factory('User', function($firebaseArray,$firebaseObject) {
var ref = new Firebase(URL);
var users = $firebaseArray(ref.child('users'));
var User = {
all: users,
create: function (user) {
return users.$add(user);
},
get: function (userId) {
return $firebaseObject(ref.child('users').child(userId));
},
delete: function (user) {
console.log("usuario: "+user.codigo)
return users.$remove(user);
}
};
return User;
});
controller where the logoff function is located:
angular.module("UnionTi").controller("homeCtrl", function($scope, $state, $location, userAuthAPI, User){
var init = function(){
$scope.usuarioLogado = userAuthAPI.getUserAuth();
/**Salva o usuario no firebase*/
User.create($scope.usuarioLogado);
}
$scope.sair = function(){
/**Recupera o usuario logado*/
$scope.usuarioLogado = userAuthAPI.getUserAuth();
/**Deleta o usuário do firebase*/
User.delete($scope.usuarioLogado)
/**Faz o logout*/
userAuthAPI.logout();
$state.go('login', {}, {reload: true});
}
init();
})
How do I delete these records?