【问题标题】:Property 'list' does not exist on type 'database' and, Property 'push' does not exist on type 'AngularFireObject<any>“数据库”类型上不存在属性“列表”,并且“AngularFireObject<any>”类型上不存在属性“推送”
【发布时间】:2018-01-09 15:43:02
【问题描述】:

我被这个错误困住了。最新版本中似乎不再存在列表方法,我无法获得任何线索来修复此错误。AngularFireObject 类型上也不存在推送方法

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 = '';
}
  }

Here is the error

【问题讨论】:

    标签: angular firebase angularfire2


    【解决方案1】:

    1) 回答您的第一个错误

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

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

    2) 回答您的第二个错误

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

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

    供我参考,请访问LINK3

    【讨论】:

      猜你喜欢
      • 2021-05-15
      • 2021-02-08
      • 2016-09-01
      • 2019-09-20
      • 2018-09-09
      • 2019-12-31
      • 1970-01-01
      • 2019-02-24
      • 2021-11-29
      相关资源
      最近更新 更多