【问题标题】:get object details of observables with angularfire2 in typescript在 typescript 中使用 angularfire2 获取 observables 的对象详细信息
【发布时间】:2017-05-22 05:43:15
【问题描述】:

在带有 angularfire2 + firebase 的 ionic2 项目中,我试图将 firebase 表中的数据转换为 .ts 文件中可用的数据。

有效:

在.ts中

this.list = af.database.list('/items');

在html中

*ngFor="let item of list | async"

这给了我所有与 {{item.val}} 一起使用的对象 但是,我想直接在脚本中使用这些数据而不是查看,所以我试图通过在 typescript 中订阅的变量来访问它。这是目前的方法和

这不起作用:

this.af.database.list('/items/', { preserveSnapshot: true } )
  .subscribe(snapshots => 
  {
    snapshots.forEach(snapshot => 
    {
      if ( !someList.some(x=>x==snapshot.key) ) 
      {
          someList.push(snapshot.key);
          console.log(snapshot.val());

          this.af.database.object('/items/'+snapshot.key, { preserveSnapshot: true } ) 
          .subscribe( item => 
          {
            console.log(item.val();
          });
      }

    })
  });

它为控制台中的每个项目记录 [object Object]。

我不明白如何在不触及 html 的情况下获得可观察对象返回的 [object Object] 的内容,最好的情况是 item.value 一样简单?

我找到了一些带有 .map 的示例,它为我返回了 TypeError: item.map is not a function。

如何获取这些对象的内容?

感谢任何帮助或测试提示 谢谢你

【问题讨论】:

标签: typescript firebase firebase-realtime-database ionic2 angularfire2


【解决方案1】:

现在实际上使用地图对我有用;它必须被投射到列表而不是对象上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多