我开始使用流星,这似乎对我的使用很好,发生问题的地方只有我的文档只有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