I'm working on web project with Angular connected with Firebase console and I used this function defined in my service class to verify if the value exists in the database before saving, When I call this function in my component I usually get undefined value.
This is my service function :
ifExist(category : CategoryType){
firebase.database().ref("/categories/").child("categories").orderByChild("category_name").equalTo(category.category_name)
.once( "value" , snapshot => {
if (snapshot.exists()){
const userData = snapshot.val();
console.log("exists!", userData);
return true;
}
return false;
});
}