[英]Ionicv2 Angularfire2 v5 I cant create new items with push
I have a ionic app and I just updated to the new angularfire2 version 5 where FirebaseListObservable was removed. 我有一个离子应用程序,我刚刚更新到新的angularfire2版本5,其中删除了FirebaseListObservable。
Now I initialize like this: 现在,我像这样初始化:
items: Observable<any>;
constructor(public navCtrl: NavController, public alertCtrl: AlertController, af: AngularFireDatabase, public actionSheetCtrl: ActionSheetController) {
this.items = af.list('/items').valueChanges();
}
Before the removal of FirebaseListObservable i only did 在删除FirebaseListObservable之前,我只做过
items: FirebaseListObservable<any>;
Before I had the ionic Actionsheet handler to create a new item and just push it to the node of the database: 在使用ionic Actionsheet处理程序创建新项目并将其推送到数据库节点之前,请执行以下操作:
addItem(){
let prompt = this.alertCtrl.create({
title: 'Name',
message: "",
inputs: [
{
name: 'title',
placeholder: 'Name'
},
],
buttons: [
{
text: 'Cancel',
handler: data => {
}
},
{
text: 'Save',
handler: data => {
this.items.push({
title: data.title
});
}
}
]
});
prompt.present();}
But the "this.items.push({" function does not work anymore. How can I push new items to the database again? 但是“ this.items.push({”函数不再起作用。如何将新项目再次推入数据库?
Before with the FirebaseListObservable it was no problem. 在使用FirebaseListObservable之前,这没有问题。 The error message I get right now is: _this.items.push is not a function
我现在得到的错误消息是:_this.items.push不是函数
but somehow I dont find the replacement for it. 但不知何故我找不到它的替代品。
fyi: I am not so good with observables and response. 菲:我对可观察性和反应性都不满意。 So please let me know in Detail if the problem is in there.
因此,请让我详细了解是否存在问题。
You are missing angularfire2 syntax. 您缺少angularfire2语法。
af.list('/items').valueChanges()
returns Observable<{}[]>
instead of FirebaseListObservable<any>
. af.list('/items').valueChanges()
返回Observable<{}[]>
而不是FirebaseListObservable<any>
。
So try with following: 因此,请尝试以下操作:
items: Observable<any>;
itemsRef: AngularFireList<{}>;
constructor(public navCtrl: NavController, public alertCtrl: AlertController, af: AngularFireDatabase, public actionSheetCtrl: ActionSheetController) {
this.itemsRef = af.list('/items');
this.items = this.itemsRef.valueChanges();
}
And then please update add section, 然后请更新添加部分,
addItem(){
let prompt = this.alertCtrl.create({
title: 'Name',
message: "",
inputs: [
{
name: 'title',
placeholder: 'Name'
},
],
buttons: [
{
text: 'Cancel',
handler: data => {
}
},
{
text: 'Save',
handler: data => {
this.itemsRef.push({
title: data.title
});
}
}
]
});
prompt.present();
}
I recommend you to read this angularfire2 guide few more. 我建议您多阅读本angularfire2指南 。 Good luck.
祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.