Email user does not appear in [METEOR] template!

I have a user index and you want to display information about each user. The user ID is displayed well, but the application does not show emails.

Here is my template:

<template name="users">
  <h1>List of all users</h1>
  {{#each users}}
    <div class="list_item">
      <p>ID: {{_id}}</p>
      <p>Email: {{email}}</p>
    </div>
  {{/each}}
</template>

And here are my routes:

Router.route('/users', function () {
  this.render('users');
}, {
  waitOn: function() {
    return [
      Meteor.subscribe('users')
    ]
  },

  data:  {users: Meteor.users.find({})}
});

And finally, my post:

Meteor.publish('users', function () {
  return Meteor.users.find({}, {fields: {emails: 1, profile: 1}});
});

Any ideas?

+4
source share
2 answers

The correct way to display an email message is:

<p>Email: {{emails.[0].address}}</p>

Email addresses are stored as an array in the user object.

You can check by typing Meteor.user()in the console:

Object {
  ...
  emails: Array[1]
    0: Object{
      address: "username@domain.com",
      verified: false
    }
  ...
}
+5
source
{{ currentUser.emails.[0].address }}
0
source

All Articles