这是我的.ts文件,我不知道为什么我得到上面的错误。 addClick方法的推送下方有一条红色虚线。
我按照教程进行操作,就像那个人做的一样……
object() 是一种方法 AngularFireDatabase 类:
object()
AngularFireDatabase
object<T>(pathOrRef: PathReference): AngularFireObject<T> { const ref = getRef(this.database, pathOrRef); return createObjectReference<T>(ref, this); }
https://github.com/angular/angularfire2/blob/master/src/database/database.ts#L37
因为它是类型 AngularFireObject 那么你可以使用以下方法:
AngularFireObject
method 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).
https://github.com/angular/angularfire2/blob/master/docs/rtdb/objects.md#api-summary
因此,没有 push() 方法。
push()
在您的代码中,您似乎只想添加数据,因此您可以使用 push() 在里面 AngularFireList 。例:
AngularFireList
const itemsRef = db.list('items'); itemsRef.push({ name: newName });
阅读文档:
https://github.com/angular/angularfire2/blob/master/docs/rtdb/lists.md