Ad

How To Pass Console Log Data Into Object In Ionic3 And Firebase

my code below gets all the dynamic data from firebase, and I want to pass all the object into another page when onClick event is initiated

public placeref = firebase.database().ref('cart');

placeOrd(){
  this.placeref
  .once('value')
  .then(snapshot => snapshot.val())
  .then(items => console.log(items)); 

}

page where I want to pass the data

  item : Item

  ionViewDidLoad() {
    console.log('ionViewDidLoad PlacedPage');
    this.navParams.get('item');

    console.log(this.navParams.get('item'));
  }

my Html file where placeOrd is Initiated

 <ion-list *ngFor="let item of orderList$ | async">
        <ion-item>
          <ion-label text-wrap>
            <h2 style="font-weight: bold">{{item?.name}}</h2>
          <!--  <ion-input type="hidden"  [(ngModel)]="placed.name" [value]="item?.name">{{item?.name}}</ion-input>-->
            <p  style="color: black">Quantity :  {{item?.qty}}</p>
           <!-- <ion-input type="hidden"  [(ngModel)]="placed.qty" [value]="item?.qty">{{item?.qty}}</ion-input>-->
             <p style="color: black">Price :  {{item?.price}}</p>
             <p class="pr" style="font-weight: bold; color: black">Total :</p><p class="pr" style="color: red"> {{item?.total}}</p>
             <button ion-button block clear color="default" (click)="removeItem(item)" >Delete Order</button>
          </ion-label>

        </ion-item>
      </ion-list>
      <p style="color: black;">Total Vat(12%) : {{vatTotal}}</p>
      <p style="color: black">Price Subtotal : {{priceTotal}}</p>
      <label style="font-weight: bold; font-size: 18px;">Order Total :</label>
      <ion-input type="number" [value]="vatTotal + priceTotal" required="true" disabled="true" style="font-size: 18px;">{{vatTotal + priceTotal}}</ion-input>
     <button ion-button block clear (click)="placeOrd()">Submit Order</button>

console log output where all my dynamic data where called

Ad

Answer

In my case, this works perfectly. so, you can try this:

public placeref = firebase.database().ref('cart');

    placeOrd(){
      this.placeref
      .once('value')
      .then(snapshot => snapshot.val())
      .then(items => {
         this.navCtrl.push('PlacedPage',{item:items});
       }); 
    }
Ad
source: stackoverflow.com
Ad