Angular firebase数据库快照和值更改

时间:2018-05-04 14:26:28

标签: database angular firebase

获得了一个与this.ShowVisualContent()合作的函数:

  getUploads() {
    this.uploads = this.db.list(`profile/${this.auth.userId}/projects/`).snapshotChanges().map((actions) => {
      return actions.map((a) => {
        const data = a.payload.val();
        this.showVisualContent(data.url, data.name);
        const $key = a.payload.key;
        const $ref = a.payload.ref;
        return { $key, ...data, $ref };
      });
    });
    return this.uploads;
  }

现在我又得到了另一个我想做同样但有价值变化的人:

  this.uploads = this.db.list(`profile/${this.auth.userId}/projects/${this.projectId}`).valueChanges();

如何让两者都这样做?

编辑:

尝试1:

 upload: Observable<Project[]>;
  this.upload = this.db.list(`profile/${this.auth.userId}/projects/${this.projectId}`).valueChanges().map(data => {
      this.navSrv.showVisualContent(data.url, data.name);
      return data;
    });

错误:

  

输入'Observable []&gt;'不可分配   输入'Observable'。类型   'AngularFireAction []'不能分配给类型   '项目[]'。

enter image description here

1 个答案:

答案 0 :(得分:0)

this.db.list(`profile/${this.auth.userId}/projects/${this.projectId}`).valueChanges().subscribe 
( res => console.log (res), 
error => console.log (error), 
() => console.log ("complete") );