流星:Minimongo不与MongoDB同步 [英] Meteor: Minimongo does not synchronize with MongoDB
问题描述
我使用Angular 2和Typescript的Meteor应用程序似乎没有在客户端加载服务器数据:我已经遵循了
My Meteor application using Angular 2 and Typescript seems not to load the server data on the client side: I have followed this tutorial, both with autopublish turned on and of, but each time several tries to display data on client side with different collections failed.
与本教程(RC4)不同,我使用的是Angular 2 RC5.我客户的main.ts如下:
Unlike in the tutorial (RC4), I am using Angular 2 RC5. My clients' main.ts looks as following:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
现在,我尝试使用集合"parties"(已启用自动发布)从教程中复制非常简单的示例.
Now I tried to copy the very simple sample from the tutorial using the collection "parties" (autopublish turned on).
我创建了文件/collections/parties.collection.ts :
import {Mongo} from 'meteor/mongo';
import {Party} from '../interfaces/party.interface';
export const Parties = new Mongo.Collection<Party>('parties');
我没有使用app.component.ts,而是将集合绑定到另一个现有的功能组件中,如下所示:
Instead of using the app.component.ts, I bind the collection in an another existing and functional component which looks like following:
import { Component } from '@angular/core';
import { Mongo } from 'meteor/mongo';
import template from './my-component.component.html';
import { Parties } from '../../../both/collections/parties.collection';
import { Party } from '../../../both/interfaces/party.interface';
@Component({
selector: 'my-selector',
template
})
export class MyComponent
{
parties: Mongo.Cursor<Party>;
constructor() {
this.parties = Parties.find();
alert(this.parties.count());
}
}
如果我在mongo控制台中调用 db.parties.find({}); ,它将返回三行,因为我已经从示例中设置了服务器端插入.
If I call db.parties.find({}); in the mongo console, it returns three rows, because I have set up the server side inserts from the sample.
我的html模板与本教程中的模板相同:
My html template is the same as in the tutorial:
<ul>
<li *ngFor="let party of parties">
<a [routerLink]="['/party', party._id]">{{party.name}}</a>
<p>{{party.description}}</p>
<p>{{party.location}}</p>
<button (click)="removeParty(party)">X</button>
</li>
alert(this.parties.count())返回"0"-都尝试使用Mongo.Cursor和Mongo.Cursor.我也尝试获取游标并警告数组.每次我得到"0"并且错误消息"NgFor只支持绑定到数组等Iterables." ,但是我认为它失败了,因为客户端无法获取服务器拥有的数据.>
alert(this.parties.count()) returns "0" - both trying Mongo.Cursor and Mongo.Cursor. I have also tried to fetch the cursor and to alert the array. Each time I get "0" and the error message "NgFor only supports binding to Iterables such as Arrays.", but I think it fails because the client does not get the data the server has.
推荐答案
在angular2.0流星的最新版本中,这不再是问题.
This is no more an issue on recent versions of angular2.0-meteor.
这篇关于流星:Minimongo不与MongoDB同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!