2016-10-03 5 views
0

meteor/MongoDBでIonic 2を使用しています。Meteor:グローバルオブジェクトが更新されない

私は次のことを行うと、それはlocalChatCollectionchatオブジェクトをinserts

 let promise: Promise<Mongo.Collection<Chat>> = this.findChats(); 
     promise.then((data: Mongo.Collection<Chat>) => { 

     let localChatCollection: Mongo.Collection<Chat> = new Mongo.Collection<Chat>(null); 
     data.find().forEach(function (chat: Chat) { 
      console.log('==> ' + chat); 
      localChatCollection.insert(chat); 
     }); 

私はグローバルlocalChatCollectionを定義する場合は、それがないinsertchatオブジェクトを行います。エラーはありませんが、プロセスはinsert行で停止します。

private localChatCollection: Mongo.Collection<Chat> = new Mongo.Collection<Chat>(null); 
.... 
     this.localChatCollection.insert(chat); 

私はこれがグローバルに定義されたcollectionに挿入する方法を得ることができます任意のアイデア?

答えて

0

これは動作しますが、私はそれが最もエレガントな解決策であるとは思わない:

 let that = this; 
     data.find().forEach(function (chat: Chat) { 
      that.localChatCollection.insert(chat); 
     }); 
関連する問題