# Having trouble saving multiple items to an array and than pushing it to another page and displaying it

**URL:** <https://forum.ionicframework.com/t/having-trouble-saving-multiple-items-to-an-array-and-than-pushing-it-to-another-page-and-displaying-it/89712>\
**Category:** ionic-v3\
**Created:** [May 10, 2017, 7:55pm UTC](https://forum.ionicframework.com/t/having-trouble-saving-multiple-items-to-an-array-and-than-pushing-it-to-another-page-and-displaying-it/89712 "2017-05-10T19:55:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nb1990](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@nb1990](https://forum.ionicframework.com/u/nb1990)\
**Post date:** [May 10, 2017, 7:55pm UTC](https://forum.ionicframework.com/t/having-trouble-saving-multiple-items-to-an-array-and-than-pushing-it-to-another-page-and-displaying-it/89712/1 "2017-05-10T19:55:05Z")

</div>

To keep it short I am creating a shopping cart like browser app. How its suppose to work:

1. 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>
```

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [May 10, 2017, 8:29pm UTC](https://forum.ionicframework.com/t/having-trouble-saving-multiple-items-to-an-array-and-than-pushing-it-to-another-page-and-displaying-it/89712/2 "2017-05-10T20:29:32Z")

</div>

> [@nb1990](#):
>
> this.navCtrl.push(ConfirmOrderPage, item);

If `item` is naked there, there’s no way for the receiving end to know that it’s called ‘item’, so you need to do this:

```auto
this.navCtrl.push(ConfirmOrderPage, {item: item});

```

---

<div class="post-metadata">

**Author:** ![nb1990](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@nb1990](https://forum.ionicframework.com/u/nb1990)\
**Post date:** [May 10, 2017, 8:32pm UTC](https://forum.ionicframework.com/t/having-trouble-saving-multiple-items-to-an-array-and-than-pushing-it-to-another-page-and-displaying-it/89712/3 "2017-05-10T20:32:46Z")

</div>

I actually noticed I was only passing a single item I wanted to pass the whole items array so I could print it out

I edited my OP to  
`this.navCtrl.push(ConfirmOrderPage, this.items);`

So now it pushes the `items` object array and not just the single item. Will I still be able to pass the array the same way

`this.navCtrl.push(ConfirmOrderPage, {items: items});`

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [May 10, 2017, 8:36pm UTC](https://forum.ionicframework.com/t/having-trouble-saving-multiple-items-to-an-array-and-than-pushing-it-to-another-page-and-displaying-it/89712/4 "2017-05-10T20:36:17Z")

</div>

Yes, that same general strategy will work (although you will need `{items: this.items}`).

---

<div class="post-metadata">

**Author:** ![nb1990](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@nb1990](https://forum.ionicframework.com/u/nb1990)\
**Post date:** [May 10, 2017, 8:38pm UTC](https://forum.ionicframework.com/t/having-trouble-saving-multiple-items-to-an-array-and-than-pushing-it-to-another-page-and-displaying-it/89712/5 "2017-05-10T20:38:48Z")

</div>

It worked! Thank you!

I will update the OP in case anybody needs help in the future.

---

<div class="post-metadata">

**Author:** ![krizim](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/krizim/32/122062_2.png) [@krizim](https://forum.ionicframework.com/u/krizim)\
**Post date:** [October 8, 2018, 6:08am UTC](https://forum.ionicframework.com/t/having-trouble-saving-multiple-items-to-an-array-and-than-pushing-it-to-another-page-and-displaying-it/89712/6 "2018-10-08T06:08:31Z")

</div>

I have the same issue the check out cant print the meltable items when send it the dashboard, what should I do?

Thanks,
