How to make alert with name of child firebase?

Hi every body

I need to show alert with text like “Welcome USER1”.
USER1 is a value that stored in firebase database.

My tree like this

in my .ts file i used this way to get the data

public usersList: FirebaseListObservable<any>;
constructor(..., public afd: AngularFireDatabase) {}
this.usersList = this.afd.list('/users/');

So any body know how I can display the fname in alert ?

Well you need to know the user ID which is “-Kp56E…”

So if you implemented some kind of login using firebase you take the userId from it and call

this.usersList = this.afd.list('/user/" + userId);

And you should get the data from it and just access the username like so

1 Like

Thanks @kgaspar
I will try to check your solution, wish i can understand the way to solve my problem.

Is there any way I can get the fname without insert the id ?

I think there is something like foreach to get the value of all fname ?

Yeah, you get the data in a json object. Then you can easily iterate trough it.

Something in the line of

for(let user in this.userLists){
1 Like

Thank u so much

Yes I think this is the way to get the value of fname but I don’t know why it show me an error in user.fname :frowning: :cry:

The text of error " fname does not exist on type ‘string’ "

Ahh yeah my bad, that actually gets the attribute name, so thats why its a string.

for(let key in userLists)
    if (this.userLists.hasOwnProperty(key)) {
        console.log(key + " -> " + this.userLists[key]);
1 Like

thank u for helps

I could find the solution and I wrote it to help other developers in the feature.

this.usersList = this.afd.list('/Users/');
    this.usersList.subscribe(data => {
      data.forEach(user => {
        alert("Welcome " + user.fname);
1 Like