我開始使用流星,這似乎對我的使用很好,發生問題的地方只有我的文檔只有9/10次。我認爲我實施了錯誤的東西。流星收集find()/ fetch()有時候工作
我用角1.5和打字稿
我收藏獲取lib文件夾在/
import { Mongo } from 'meteor/mongo';
export const Locations= new Mongo.Collection('locations');
然後創建的集合數據導入到我的服務
import {app} from '../../js/lib/app';
import {Locations} from '../../../lib/collections';
export class LocationsService {
locations: any;
constructor(){
console.log('Constructor called');
this.locations = Locations
.find({})
.fetch();
console.log('documents loaded');
console.log(this.locations);
}
public createLocation(any:any){
Locations.insert(any);
}
public updateLocation(identity:any, modifier:any){
Locations.update(identity,modifier);
}
}
app.service('locationsService', LocationsService);
這裏是控制檯.logs from 3 different page refresh:
它看起來像文檔中我得到的金額完全隨機的。
這不是隨機的。您需要等待收集準備就緒,您可以在路線中執行此操作(如果您使用的是ui路由器) – Mikkel
您是否可以發佈有關它的更多信息? – Opaldes