如何在Ionic3中单击按钮时删除所有Firebase数据?

时间:2019-03-27 15:25:04

标签: angular ionic-framework firebase-realtime-database ionic3 angularfire2

在Ionic 3应用程序上单击按钮后,我想从Firebase中删除所有数据。

这是我的html代码 并显示一些错误,提示“无法读取属性密钥”

  <ion-list *ngFor="let item of orderList$ | async">
        <ion-item>
          <ion-label text-wrap>
             <h2 style="font-weight: bold">{{item?.name}}</h2>     
             <p  style="color: black">Quantity :  {{item?.qty}}</p>    
             <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>

            </ion-label>
        </ion-item>
        <ion-input type="hidden"  [(ngModel)]="placed.orders" [value]="namees">{{namees}}</ion-input>
      </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"  [(ngModel)]="placed.totalp" [value]="vatTotal + priceTotal" required="true" disabled="true" style="font-size: 18px;">{{vatTotal + priceTotal}}</ion-input>
      <button ion-button block clear (click)="addPlaced(placed)">Submit Order</button>
      <button ion-button block clear color="default" (click)="removeItem(item)">Delete Order</button>

这是我在ts代码中启动removeItem的地方

  removeItem(item: Item){
    this.dr.removeItem(item).then(()=>{
      this.toast.show(`${item.name} removed!`);
      this.navCtrl.setRoot(HomePage);
    });
  } 

removeItem服务

private cartlistref = this.db.list<Item>('cart');

  removeItem(item: Item){
        return this.cartlistref.remove(item.key);
    } 

我的另一个问题是,是否可以通过单击按钮删除创建的数据库列表“购物车”?

0 个答案:

没有答案