[SOLVED] Users email not displaying

Hi there,

I’m trying to display users in a list, especially their email address.

The _id is perfectly displayed. But i actually can’t display their e-mail address.

Here’s the HTML :

<template name="usersTreeView">
    <div class="col-12 align-self-end">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th scope="col"># Record ID</th>
                    <th scope="col">First</th>
                    <th scope="col">Last</th>
                    <th scope="col">Handle</th>
                </tr>
            </thead>
            <tbody>
                {{#each users}}
                <tr>
                    <th scope="row">{{@index}}</th>
                    <td>{{_id}}</td>
                    <td>{{email}}</td>
                    <td>@twitter</td>
                </tr>
                {{/each}}
            </tbody>
        </table>
    </div>
</template>

And here’s the JS helper :

Template.usersTreeView.helpers({
    users: () => {
        return Meteor.users.find({});
    },
    email: () => {
        return this.emails[0].address;
    }
});

I followed this topic : Meteor novice-- display list of user emails ,
but i wasn’t able to display the e-mail …

Here’s my result :

Thanks a lot !

B.

Try using function() { } instead of () => {}

They have different meanings when you’re using this.

1 Like

Worked … I’ll read MDN to know what it implies. Well, 2nd thanks in a row, i wouldn’t have found this alone !

@cereal, could i ask you one more thing : It works, perhaps i’m only seing the connected user. I’ve created a 2nd one, but it do not display. When i disconnect / reconnect with the 2nd user, i then see the 2nd user in list, but not the first one ?

You probably have to publish all the users.

// server/main.js
Meteor.publish('users', function() {
  return Meteor.users.find({});
});

// client/main.js
Meteor.subscribe('users');

The way the pub/sub model works is when you subscribe to data, you actually pull all of the data that the publish call returns. It’s like doing a get request that returns all of your users, and storing it in a variable.

Without the subscribe, you haven’t pulled any data to work with.

1 Like

That’s exactly what i have in my server file :


Meteor.startup(() => {
    // Nothing here
});

Meteor.publish('users', function () {
    return Meteor.users.find({});
});

But only one user is displayed :confused:

Do you subscribe to it anywhere?

1 Like

Yes here :

Template.usersTreeView.onCreated(function() {
    var self = this;
    self.autorun(function() {
        self.subscribe('users');
    })
});

EDIT : My bad, it was a wrong file import ! Thanks for your support, it helped me !

1 Like