To keep it short I am creating a shopping cart like browser app. How its suppose to work:
- User selects a product, at which point they are brought to the cart page.
- They can add the product to there cart, at which point they are redirected to the products page so they can add another product OR
- They can click the checkout button and they are brought to a order confirmation page where they can view every item in their cart
Problem: The array of items is passed in the additem()
method to the ConfirmOrder
but it is not printing out
Edit: Here is the working code. Thank you @rapropos
in my cart.ts file (The saveItem() method gets called when user presses the add to cart button
public items = [];
// Both of these params which are to be saved in the array are passed from another page
prodName: string = this.navParams.get('prodName');
prodDesc: string = this.navParams.get('prodDesc');
saveItem() {
let newItem = {
prodName: this.prodName,
prodDesc: this.prodDesc
};
this.addItem(newItem);
}
addItem(item) {
this.items.push(item);
this.navCtrl.push(ConfirmOrderPage, items: this.items);
}
ConfirmOrder.ts
export class ConfirmOrderPage {
prodName;
items = [];
constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad ConfirmOrder');
this.items = this.navParams.get('items');
}
}
ConfirmOrder.html
<ion-list>
<ion-item *ngFor="let item of items">{{item.prodName}}</ion-item>
</ion-list>