Reputation: 81
I am using the ionic framework.I want to display all the users stored in my firebase database in the form of a list on a page. The way i am storing these users is by their uid like this :
user
|_uid1
| |_email:value
| |_tag:value
|_uid2
| |_email:value
| |_tag:value
|_...
The problem i'm facing is that i don't know how to retrieve all the users and how to go through them one by one, displaying everybody's email ids. How do i do it in typescript or javascript? Please Help !
Upvotes: 1
Views: 943
Reputation: 603
HERE is code snippet which i used to get all the users (user class can have any structure) from fire base.
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference("users");
DatabaseReference df = mDatabase.child("user");
df.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
AllUserlist.clear();
for(DataSnapshot d : dataSnapshot.getChildren()) {
User user = new User();
HashMap<String,Object> map= (HashMap<String, Object>)d.getValue();
Gson gson = new Gson();
JsonElement jsonElement = gson.toJsonTree(map);
user = gson.fromJson(jsonElement, User.class);
AllUserlist.add(user);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
AllUserlist will have all the users data including the email which you need. Hope it helps !!
Upvotes: 1