1
I am developing a small chat using the Firebase. My intention was to do the login
in my application and save the usuarioLogado
in the database and by logoff
delete this user from the database.
Currently I can only save the user at login time, at delete time simply nothing happens, no error happens too, 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;
});
In the 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 erase these records?