I am new with Firebase. I am developing an angular + firebase application, where after registering a user by email + password, he can save his username after sending the profile form.
Before that, I want to know if the user in the application has his username. This aproch does not work, because scope.used is always false:
scope.used = false; scope.updateProfile = function(profile) { var ref = new Firebase(FIREBASE_URL + '/users'); ref.orderByChild("username").equalTo(profile.username).on("child_added", function(snapshot) { if (currentUser != snapshot.key()) { scope.used = true; } }); if (scope.used) { console.log('username already exists'); } };
Is there any other way to do this?
EDIT (I answer to myself)
This approach works:
scope.used = false; var userRef = new Firebase(FIREBASE_URL + '/users/' + currentUser); scope.updateProfile = function(profile) { var ref = new Firebase(FIREBASE_URL + '/users'); ref.orderByChild("username").equalTo(profile.username).on("child_added", function(snapshot) { if (currentUser != snapshot.key()) { scope.used = true; } }); ref.orderByChild("username").equalTo(profile.username).once("value", function(snap) {
angularjs firebase
manguiti Feb 25 '16 at 19:40 2016-02-25 19:40
source share