this.db.object( ).push不是Ionic中的函数


v-star*위위
2025-03-12 03:06:52 (9天前)


这是我的.ts文件,我不知道为什么我得到上面的错误。 addClick方法的推送下方有一条红色虚线。

我按照教程进行操作,就像那个人做的一样……

2 条回复
  1. 0# 解天 | 2019-08-31 10-32




    object()

    是一种方法

    AngularFireDatabase

    类:




    1. object(pathOrRef: PathReference): AngularFireObject {
      const ref = getRef(this.database, pathOrRef);
      return createObjectReference(ref, this);
      }

    2. </code>



    https://github.com/angular/angularfire2/blob/master/src/database/database.ts#L37



    因为它是类型

    AngularFireObject

    那么你可以使用以下方法:




    1. method

    2. set(value: T) Replaces the current value in the database with the new value specified as the parameter. This is called a destructive update, because it deletes everything currently in place and saves the new value.
      update(value: T) Updates the current value with in the database with the new value specified as the parameter. This is called a non-destructive update, because it only updates the values specified.
      remove() Deletes all data present at that location. Same as calling set(null).

    3. </code>



    https://github.com/angular/angularfire2/blob/master/docs/rtdb/objects.md#api-summary



    因此,没有

    push()

    方法。





    在您的代码中,您似乎只想添加数据,因此您可以使用

    push()

    在里面

    AngularFireList

    。例:




    1. const itemsRef = db.list(‘items’);
      itemsRef.push({ name: newName });

    2. </code>


    阅读文档:




    https://github.com/angular/angularfire2/blob/master/docs/rtdb/lists.md


登录 后才能参与评论