1

I don't know why this code cannot run, but another way is ok

this.usersRef = this.database.ref('/doctors/' + firebase.auth().currentUser.uid + '/userList');
    this.UsersRef.on('value', function(snapshot){
       console.log(snapshot.val());
        snapshot.forEach(function (child) {
            // console.log(child.key);
            var val = child.val();
            this.displayUserInfo(child.key, val.email, val.firstname, val.lastname);
        });
    });

It always shows "Cannot read property ‘displayUserInfo’ of undefined",

And this way is ok:

    var setUsersInfo = function (data) {
    var val = data.val();
    this.displayUserInfo(data.key, val.email, val.firstname, val.lastname);
}.bind(this);
this.usersRef.limitToLast(12).on('child_added', setUsersInfo);
this.usersRef.limitToLast(12).on('child_changed', setUsersInfo);

I think the point is bind(this) in javascript, but I tried .bind(this) in the first way, and it cannot work.

Could anyone give some hints about it? Thank you

0 Answers0