我正在用accounts-password 包编写一个meteor-angular2 项目。
我正在尝试确定用户是否已登录,如果已登录,则发布内容。
这是我的打字稿代码:
import {Meteor} from 'meteor/meteor';
import {RoomsCollection} from "../collections/rooms";
Meteor.publish('rooms',()=>{
if (!this.userId) {
return null;
} else {
return RoomsCollection.find();
}
});
如您所见,我正在使用this.userId
,但似乎this
未定义。
这是错误:
TypeError: Cannot read property 'userId' of undefined
我不太明白匿名函数如何具有this.userId
,我实际上正在阅读 2014 年的“You First Meteor Application”一书。所以也许他们在哪里发生了重大变化……或者我错过了一些东西。
我是 Meteor 的新手,因此我们将不胜感激有关该问题的任何信息。