类型“数据库"上不存在属性“列表",并且类型“AngularFireObject<任何"上不存在属性“推送". [英] Property &#39;list&#39; does not exist on type &#39;database&#39; and, Property &#39;push&#39; does not exist on type &#39;AngularFireObject&lt;any&gt;

查看:35
本文介绍了类型“数据库"上不存在属性“列表",并且类型“AngularFireObject<任何"上不存在属性“推送".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被这个错误困住了.似乎最新版本中不再存在 list 方法,我无法获得任何解决此错误的线索.此外,AngularFireObject 类型不存在 push 方法

I am stuck on this error. It seems list method no longer exist in latest version and I am not able to get any clue to fix this error.Also push method does not exist on type 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 = '';
}
  }

这里是错误

推荐答案

1) 回答你的第一个错误

1) Answer for your first error

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

You need to use af.list() instead of af.database.list() as it does not exist in recent updates

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

And according to recent updates you need query the list as shown in the links: LINK1 LINK2 The above links will show you how to declare list and query them.

2) 回答你的第二个错误

2) Answer for your second error

在最近的对象更新中,没有这种 push() 方法.

There is no such method for push() in the recent update for objects.

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

Only three methods exists under AngularFireObject: set(value: T), update(value: T) and remove()

作为我的参考,请访问此LINK3

For my reference visit this LINK3

这篇关于类型“数据库"上不存在属性“列表",并且类型“AngularFireObject<任何"上不存在属性“推送".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆