I was working with user accounts in meteor when I started get an error. The error is printed in the console is in my userEmail helper function.
My question is if it is undefined then why am I getting an output?
My html code:
{{#each user}}
{{#if student}}
<div class="row">
<div class="user-wrapper">
<div class="row">
<div class="name-wrapper col-md-3">
<span class="head">{{profile.firstname}}</span>
</div>
<div class="email-wrapper col-md-3">
<span class="head">{{userEmail}}</span>
</div>
<div class="email-wrapper col-md-3">
<span class="head">{{>starsRating mutable=true class="js-rate-images" id=_id}}</span>
</div>
<div class="email-wrapper col-md-3">
<span class="head">Remark</span>
<button class="btn btn-primary">Enter Remark</button>
</div>
</div>
</div>
</div>
{{/if}}
{{/each}}
My helper functions are:
Template.Users.helpers({
user: function(){
return Meteor.users.find();
},
userEmail:function(){
return this.emails[0].address;
},
student:function(){
return this.profile.profession === 'student';
}
});
Your function is running before the Collection is loaded, but since Meteor helper is Reactive, you get the result once the collection is loaded.
One way to prevent that message is to run your code conditionally: