【问题标题】:Acessing the json data from firestore with angular使用 Angular 从 Firestore 访问 json 数据
【发布时间】:2019-02-27 14:26:32
【问题描述】:

我正在尝试以角度访问 firestore 数据库中的数据。

这是我的组件:

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';

import {AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument} from 'angularfire2/firestore';



interface Mission {
  cliente: string;
  luogo: string;
  materiale: string;
  nCassoni: number;
  nota: string;
  operatore: string;
}


@Component({
  selector: 'app-check-mission',
  templateUrl: './check-mission.component.html',
  styleUrls: ['./check-mission.component.css']
})
export class CheckMissionComponent{

  missionsCol: AngularFirestoreCollection<Mission>;
  missions: any;


  constructor(private db: AngularFirestore) {

  }

  ngOnInit(){
    this.missionsCol = this.db.collection('mission');
    this.missionsCol.valueChanges().subscribe((_missions: any) => {
      this.missions = _missions;
    console.log(this.missions);
  }


}

这是我的 html:

<ul *ngFor="let mission of missions | async">
    <li>
        {{ mission.cliente }}
    </li>
</ul>

在 Firestore 中,我在 mission 下有 6 个文档,实际上在 html 页面中我看到了六个点,但除了一切都是空白的!

我做错了什么?

更新

--我已经更新了代码,现在我可以在控制台中记录结果,但是我看不到 html 中的 deata。 控制台给了我这个错误nvalidPipeArgument: '[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]' for pipe 'AsyncPipe' at invalidPipeArgumentError ..

【问题讨论】:

    标签: json angular google-cloud-firestore


    【解决方案1】:

    试试这个:

    this.missionsCol.valueChanges().subscribe((_missions: any) => {
      this.missions = _missions;
    })
    

    每次更改任务 json 中的某些内容时都会触发一个注释。

    【讨论】:

    • 感谢您的评论,我正在进入控制台InvalidPipeArgument: '[object Object]..
    • 可能是因为missions: Observable&lt;Mission[]&gt;;需要missions: any;
    • 我已经用你的建议更新了上面的代码,你能告诉我我是否在错误的地方插入了一些东西吗?因为我试过了,但我不能让它工作
    猜你喜欢
    • 2023-04-01
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多