使用angular

时间:2019-02-27 14:26:32

标签: json angular google-cloud-firestore

我正在尝试从角度访问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页面中,我实际上看到了6点,但是除了所有内容都是空白!

我做错了什么?

更新

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

1 个答案:

答案 0 :(得分:0)

尝试一下:

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

请注意,每当任务json中的某些内容发生更改时,此选项就会触发。