类型'database'上不存在属性'list',并且'AngularFireObject <any>类型上不存在属性'push'

时间:2018-01-09 15:43:03

标签: angular firebase angularfire2

我坚持这个错误。似乎list方法在最新版本中不再存在,我无法得到任何线索来修复此错误。而且类型AngularFireObject上也不存在push方法

import { Component } from '@angular/core';
import { AngularFireDatabase, AngularFireObject } from "angularfire2/database"; 

import { AngularFireAuth,} from 'angularfire2/auth';
import { Observable } from 'rxjs/Observable';
import * as firebase from 'firebase/app';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  items: AngularFireObject<any>;
  name: any;
  msgVal: string = '';
  title = 'app';
  constructor (public afAuth: AngularFireAuth, public af: AngularFireDatabase) {
    this.items = af.database.list('/messages', {
      query: {
        limitToLast: 5
      }
    });

    this.af.auth.subscribe(auth => { 
      if(auth) {
        this.name = auth;
      }
    });

  }

  login() {
    this.afAuth.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider());
  }
  chatSend(theirMessage: string) {
    this.items.push({ message: theirMessage, name: this.name.facebook.displayName});
    this.msgVal = '';
}
  }

enter image description here

1 个答案:

答案 0 :(得分:1)

1)回答第一个错误

您需要使用af.list()而不是af.database.list(),因为它在最近的更新中不存在

根据最近的更新,您需要查询链接中显示的列表: LINK1 LINK2 以上链接将向您展示如何声明列表并查询它们。

2)回答第二个错误

最近的对象更新中没有push()方法。

AngularFireObject下只存在三种方法:set(value:T),update(value:T)和remove()

如需参考,请访问LINK3

相关问题