Reference.push失败:第一个参数包含属性中的undefined [英] Reference.push failed: first argument contains undefined in property
问题描述
我正在尝试将两个数据(itemName和itemAmout)发送到firebase数据库但是它给了我这个错误:
引用:错误:Reference.push失败:第一个参数在属性'shoppingItem.itemName'中包含undefined
我不知道问题的来源。
这是我的代码:
addItem.ts:
import {组件}来自'@ angular / core';
从'ionic-angular'导入{IonicPage,NavController,NavParams};
从'../../models/items.interface'导入{ShoppingItems};来自'angularfire2 / database'的
import {AngularFireDatabase};来自'angularfire2 / database'的
import {AngularFireList};
@IonicPage(
{
segment:'shoppingList / Add-Item'
}
)
@Component( {
选择器:'page-add-item',
templateUrl:'add-item.html',
})
导出类AddItemPage {
shoppingItem = {} as ShoppingItems;
shoppingListRef $:AngularFireList< ShoppingItems> ;;
构造函数(public navCtrl:NavController,public navParams:NavParams,
private adb:AngularFireDatabase){
this.shoppingListRef $ = adb.list ( '/ shoppingItem');
}
addItem(shoppingItem:ShoppingItems){
this.shoppingListRef $ .push({
itemName:this.shoppingItem。 itemName,
itemAmount:Number(this.shoppingItem.itemAmount)
});
//this.shoppingItem= {}作为ShoppingItems;
this.navCtrl.pop();
}
}
items.interface.ts:
导出界面ShoppingItems {
itemName:string;
itemAmount:number;
}
addItem.html:
< ;离子报头GT;
< ion-navbar color =dark>
< ion-title>添加商品< / ion-title>
< / ion-navbar>
< / ion-header>
< ion-content padding>
< ion-item>
< ion-label floating>
商品名称
< / ion-label>
< ion-input type =text([ngModel])=shoppingItem.itemName>< / ion-input>
< / ion-item>
< ion-item>
< ion-label floating>
商品金额
< / ion-label>
< ion-input type =number([ngModel])=shoppingItem.itemAmount>< / ion-input>
< / ion-item>
< button ion-button block(click)=addItem(shoppingItem)>添加项目< / button>
< / ion-content>
我的尝试:
我试图使用此解决方案,但它只会在不将数据发送到我的firebase数据库的情况下删除错误消息。
:AngularFireList< ShoppingItems> ;;
构造函数(public navCtrl:NavController,public navParams:NavParams,
private adb:AngularFireDatabase){
this.shoppingListRef
= adb.list( '/ shoppingItem');
}
addItem(shoppingItem:ShoppingItems){
this.shoppingListRef
.push({
itemName:this.shoppingItem.itemName,
itemAmount:Number(this.shoppingItem.itemAmount)
});
//this.shoppingItem= {}作为ShoppingItems;
this.navCtrl.pop();
}
}
items.interface.ts:
导出界面ShoppingItems {
itemName:string;
itemAmount:number;
}
addItem.html:
< ;离子报头GT;
< ion-navbar color =dark>
< ion-title>添加商品< / ion-title>
< / ion-navbar>
< / ion-header>
< ion-content padding>
< ion-item>
< ion-label floating>
商品名称
< / ion-label>
< ion-input type =text([ngModel])=shoppingItem.itemName>< / ion-input>
< / ion-item>
< ion-item>
< ion-label floating>
商品金额
< / ion-label>
< ion-input type =number([ngModel])=shoppingItem.itemAmount>< / ion-input>
< / ion-item>
< button ion-button block(click)=addItem(shoppingItem)>添加项目< / button>
< / ion-content>
我的尝试:
我试图使用此解决方案,但它只会在不将数据发送到我的firebase数据库的情况下删除错误消息。
I am trying to send two data (itemName and itemAmout) to firebase database But it gives me this error:
Quote:Error: Reference.push failed: first argument contains undefined in property 'shoppingItem.itemName'
I dont know where the probleme come from.
Here is my code :
addItem.ts :
import { Component } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; import {ShoppingItems} from '../../models/items.interface'; import { AngularFireDatabase } from 'angularfire2/database'; import { AngularFireList } from 'angularfire2/database'; @IonicPage( { segment :'shoppingList/Add-Item' } ) @Component({ selector: 'page-add-item', templateUrl: 'add-item.html', }) export class AddItemPage { shoppingItem ={} as ShoppingItems ; shoppingListRef$ :AngularFireList<ShoppingItems>; constructor(public navCtrl: NavController, public navParams: NavParams, private adb:AngularFireDatabase) { this.shoppingListRef$=adb.list('/shoppingItem'); } addItem(shoppingItem:ShoppingItems){ this.shoppingListRef$.push({ itemName: this.shoppingItem.itemName , itemAmount : Number(this.shoppingItem.itemAmount) }); //this.shoppingItem={} as ShoppingItems; this.navCtrl.pop(); } }
items.interface.ts :
export interface ShoppingItems { itemName : string ; itemAmount : number; }
addItem.html:
<ion-header> <ion-navbar color="dark"> <ion-title>Add Item</ion-title> </ion-navbar> </ion-header> <ion-content padding> <ion-item> <ion-label floating> item name </ion-label> <ion-input type="text" ([ngModel])="shoppingItem.itemName"></ion-input> </ion-item> <ion-item> <ion-label floating> item amount </ion-label> <ion-input type="number" ([ngModel])="shoppingItem.itemAmount"></ion-input> </ion-item> <button ion-button block (click)="addItem(shoppingItem)">Add item</button> </ion-content>
What I have tried:
I tried to use this solution, but what it only takes away the error message without sending the data to my firebase database.
:AngularFireList<ShoppingItems>; constructor(public navCtrl: NavController, public navParams: NavParams, private adb:AngularFireDatabase) { this.shoppingListRef
=adb.list('/shoppingItem'); } addItem(shoppingItem:ShoppingItems){ this.shoppingListRef
.push({ itemName: this.shoppingItem.itemName , itemAmount : Number(this.shoppingItem.itemAmount) }); //this.shoppingItem={} as ShoppingItems; this.navCtrl.pop(); } }
items.interface.ts :
export interface ShoppingItems { itemName : string ; itemAmount : number; }
addItem.html:
<ion-header> <ion-navbar color="dark"> <ion-title>Add Item</ion-title> </ion-navbar> </ion-header> <ion-content padding> <ion-item> <ion-label floating> item name </ion-label> <ion-input type="text" ([ngModel])="shoppingItem.itemName"></ion-input> </ion-item> <ion-item> <ion-label floating> item amount </ion-label> <ion-input type="number" ([ngModel])="shoppingItem.itemAmount"></ion-input> </ion-item> <button ion-button block (click)="addItem(shoppingItem)">Add item</button> </ion-content>
What I have tried:
I tried to use this solution, but what it only takes away the error message without sending the data to my firebase database.
这篇关于Reference.push失败:第一个参数包含属性中的undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!