Javascript 使用MeteorJS采集和角度2显示数据

Javascript 使用MeteorJS采集和角度2显示数据,javascript,angular,meteor,angular2-meteor,Javascript,Angular,Meteor,Angular2 Meteor,我试图使用Rxjs Observable和.zone()方法来显示MeteorJS mongoDB集合中角度组件中的数据,但我遇到了以下错误:“无法读取未定义的属性”title“ 我正在使用从控制台添加数据 db.favorites.insert({ content: 'Second favorite content', title: 'some title', subtitle: 'subtitle' }); 有人能看到我遗漏了什么或者我需要重构什么吗?注意:我也在使

我试图使用Rxjs Observable和.zone()方法来显示MeteorJS mongoDB集合中角度组件中的数据,但我遇到了以下错误:“无法读取未定义的属性”title“

我正在使用从控制台添加数据

db.favorites.insert({
    content: 'Second favorite content',
    title: 'some title',
    subtitle: 'subtitle'
});
有人能看到我遗漏了什么或者我需要重构什么吗?注意:我也在使用离子2。 谢谢

组成部分

import { Component, ViewChild, Input, Output, EventEmitter, OnChange, Injectable} from '@angular/core';
import { Platform, ViewController, NavController, NavParams } from 'ionic-angular';
import { ProfileHeader } from '../profile-header/profile-header';
import { ContentPage } from '../../library-pages/content';
import { Observable } from 'rxjs/Observable';
import style from './profile-favorites-view.scss';

//Collection import
import { Favorites } from '../../collections/favorite';

@Component({
  directives: [ContentPage],
  template: `
  <profile-header></profile-header>
  <ion-content class="profile-option-content">
    <section class="profile-option-title-container">
    <h2 class="main-title">My favorites</h2>
  </section>

  <div>
    <ul>
      <li *ngFor="let favorite of favorites | async"></li>
      <p>{{ favorite.title }}</p>
      <p>{{ favorite.subtitle }}</p>
      <p>{{ favorite.content }}</p>
    </ul>
  </div>
  `,
  styles: [ style ]
})

export class ProfileFavorite {
  favorites: Observable<any[]>;

  constructor(public navCtrl: NavController) {
    this.favorites = Favorites.find({}).zone();
  }
}
从'@angular/core'导入{Component,ViewChild,Input,Output,EventEmitter,OnChange,Injectable};
从“离子角度”导入{Platform,ViewController,NavController,NavParams};
从“../profile header/profile header”导入{ProfileHeader};
从“../../library pages/content”导入{ContentPage};
从“rxjs/Observable”导入{Observable};
从“/profile favorites view.scss”导入样式;
//集合导入
从“../../collections/favorite”导入{Favorites};
@组成部分({
指令:[ContentPage],
模板:`
我的最爱
    {{favorite.title}}

    {{favorite.subtitle}

    {{favorite.content}

`, 样式:[样式] }) 导出类配置文件收藏夹{ 偏好:可观察; 构造函数(公共navCtrl:NavController){ this.favorites=favorites.find({}).zone(); } }
收藏

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { MongoObservable } from 'meteor-rxjs';

export type FavoritesTask = {
  _id? : string,
  content : string,
  subtitle : string,
  title : string
}

export const Favorites = new MongoObservable.Collection<FavoritesTask>( 'favorites' );

Favorites.allow({
  insert() { return true; },
  update() { return true; },
  remove() { return true; }
});

Favorites.deny({
  insert() { return false; },
  update() { return false; },
  remove() { return false; }
});
从'Meteor/Meteor'导入{Meteor};
从“meteor/Mongo”导入{Mongo};
从“meteor rxjs”导入{MongoObservable};
导出类型FavoritesTask={
_id?:字符串,
内容:字符串,
字幕:字符串,
标题:字符串
}
export const Favorites=new MongoObservable.Collection('Favorites');
收藏夹。允许({
insert(){return true;},
update(){return true;},
remove(){return true;}
});
否认({
insert(){return false;},
update(){return false;},
remove(){return false;}
});

使用
{{favorite.title}
插值等的
标记必须是
  • 标记模板的子项,在该模板中定义
    *ngFor
    循环和局部变量
    favorite

    收藏夹
    未在该循环之外定义


    他们现在是下一个兄弟姐妹,而不是孩子。

    谢谢,我重构了那个部分,所以现在标记在
  • 中。我现在没有错。但是,现在的问题是前端没有任何渲染。如果它将{{favorites}}放在*ngFor循环之外,我得到[object object],您是否也在服务器上实例化您的集合,并发布该数据(或保持
    autopublish
    )?我在Meteor.publish上阅读,它似乎指定了发送给客户端的内容。我还没有加上,所以我一定是遗漏了什么。