2016-04-28 108 views
0

我正在用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年讀的書「你第一次流星應用」,所以也許他們在哪裏突破變化......或者我失去了一些東西。

我是新來的流星,所以關於這個問題的任何信息將不勝感激。

回答

相關問題