This isn't writing to the database.
ngOnInit() {
this.route.queryParams.subscribe(params => {
const itemsRef = this.db.list('cart_checkouts');
itemsRef.push({checkoutProductName : this.product_name });
});
}
I get the error:
Error: Reference.push failed: first argument contains undefined in property 'cart_checkouts.checkoutProductName'
The query parameters are:
id, thumbnail, quantity, product_name, product_price
so product_name should be available to write to the database.
When I write
itemsRef.push({checkoutProductName : "Helmet" });
It saves "Helmet" to the database so I know that the error is in this.product_name.
I have a form that sends the query parameters like this:
<form [formGroup]="submitForm" (ngSubmit)="checkOut(items)">
<input type="submit" value="Check Out">
</form>
public checkOut(items: any) {
{ this.router.navigate(['check-out'], { queryParams: { checkouts: JSON.stringify(this.items) } });
and when I write this:
itemsRef.push({checkoutProductName : params['checkouts'] });
It gets the entire array of checkout items and saves it to checkoutProductName.
The query parameters in the url field look like this:
http://localhost:4200/check-out?checkouts=%5B%7B%22id%22:1,%22thumbnail%22:%22product-2.gif%22,%22quantity%22:2,%22product_name%22:%22Adult%20Female%20Bike%22,%22product_price%22:20.5%7D,%7B%22id%22:3
But instead of %22, there are quotation marks.
I debugged like this:
console.log("params " + params);
console.log("this.checkouts " + this.checkouts);
console.log("this.items HERE " + this.items);
console.log("params.checkouts " + params.checkouts);
const item = JSON.parse(params.checkouts);
console.log("item.product_name " + item.product_name);
console.log("params checkouts product_name " + params.checkouts["product_name"]);
and the console log returned:
params [object Object]
this.checkouts undefined
this.items HERE undefined
params.checkouts [{"id":1,"thumbnail":"product-2.gif","quantity":2,"product_name":"Adult Female Bike","product_price":20.5},{"id":3,"thumbnail":"product-4.gif","quantity":3,"product_name":"Adult Unisex Helmet","product_price":4}]
item.product_name undefined
params checkouts product_name undefined