私はmeteor0.5.4アプリを作成しました-accounts-ui、accounts-passwordを追加し、テンプレートに{{loginButtons}}を追加しましたname="hello"ブロックハットはすべてのmeteor作成に付属しています。
Chromeブラウザコンソールでこれを入力すると、これらのSOソースに従ってMeteor.user()。emails [0] .address- http : //goo.gl/MTQWu、http : //goo.gl/Cnbn7-現在ログインしているユーザーの電子メール。
同じコードをif(Meteor.isClient)セクションに入れようとすると:
Template.hello.greeting = function () {
return Meteor.user().emails[0].address;
};
私は得る:
Uncaught TypeError: Cannot read property '0' of undefined foo.js:3
Exception from Meteor.flush: TypeError: Cannot call method 'firstNode' of undefined
公開関数内にMeteor.user()を配置できない場合、ログインしたユーザーの電子メールを他にどのように取得できますか?これを共有関数にして、クライアント側関数内でMeteor.call('getEmail'、Meteor.userId())を使用して呼び出してみたところ、同様の結果が得られました。