I am not getting my array data in my next page


#1

good day,
I am developing an application like food panda and I am new to ionic framework.the problem is i m getting my restaurant data from one page to next page which is menu page and then when i am saving menu items clicked by user . this data of menu selected is not going to my order page as i am saving all menu items data in an array.

here is my code:
restmenu.ts
export class RestmenuPage {
public resturant={

id:"",name:"",image:""
};
constructor(public navCtrl: NavController, public navParams: NavParams,private loading:LoadingController,
private restmenu:ResturantmenusProvider,private share:SocialSharing,private sharerest:ActionSheetController)
{
this.resturant=this.navParams.get(“resturant”);
console.log(this.resturant);
}

public cart=[];

menus:any;
ionViewDidLoad() {
console.log(‘ionViewDidLoad RestmenuPage’);

let loading= this.loading.create({
  content:"Loading Please Wait!"
});
loading.present();
this.restmenu.getresturantmens(this.resturant.id).then(data1 => {
  this.menus= data1;

  console.log(data1);
 loading.dismiss();
 
});

}

AddtoCart(menus){
let cartdata=this.cart.push(menus);
this.cart.sort();
console.log(cartdata, this.cart.sort());

}

removetoCart(menuindex){
let del=this.cart[menuindex];
let deel=this.cart.splice(menuindex,1);
this.cart.sort();
console.log(deel,this.cart.sort());

}

gotoOrder(cart){
this.navCtrl.push(OrderPage),{

menuselected:this.cart

}

restmenu.html

{{resturant.name}}

<ion-card *ngFor=“let menu of menus ;let menuindex=index”>
<img [src]=“menu.image”>

ID:{{menu.itemName}}
{{menu.price}}
<button ion-button item-center (click)=“AddtoCart(menu)”>

  </button>
  <button ion-button item-center (click)="removetoCart(menuindex)">
      <ion-icon ios="ios-close" md="md-close"></ion-icon>
      
  </button>
  <ion-item>
    <button ion-button item-center (click)="sharemenu(menu)"
    >Share</button>
  </ion-item>

</ion-card-content>
  </ion-card>

Orderpage.ts
export class OrderPage {
public menu={

restaurantID:"",description:""

};
constructor(public navCtrl: NavController, public navParams: NavParams) {
let cart=this.navParams.get(" menu");
console.log(“this is the cart”,cart);
}

looking to hear from you guys. thanks…


#2

Do a console.log(this.navParams.data) to see what you are getting. That will tell you if you are at all passing data and what object key to include in the this.navParams.get( ) statement.

The code you submitted is incomplete to tell how you are including the data to the page you are opening through Push.


#3

One major problem is that you aren’t initializing menus (or giving it a proper type instead of abusing any), so I’m surprised that the ngFor isn’t throwing an error about trying to loop across undefined.