Skip to content

Commit

Permalink
sum cost
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasBeck777 committed Oct 23, 2022
1 parent 4ec322e commit 3139814
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src4/AngularUi/src/app/checkout/checkout.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div class="checkout">

<h2>Checkout</h2>

<!--
<ul class="orders">
<li *ngFor="let order of orders">
<button [class.selected]="order === selectedOrder" type="button" (click)="onSelect(order)" >
Expand All @@ -9,7 +11,7 @@ <h2>Checkout</h2>
</button>
</li>
</ul>

-->

<table>
<tbody>
Expand All @@ -25,9 +27,18 @@ <h2>Checkout</h2>
<td>{{item.cost}}</td>
<td>{{item.total}}</td>
</tr>
<tr>
<td>Total:</td>
<td></td>
<td></td>
<td>{{sum}}</td>
</tr>
</tbody>
</table>

<app-order-detail [order]="selectedOrder"></app-order-detail>
<button type="button" (click)="donate()">Spenden</button>
<button type="button" (click)="receive()">Erhalten</button>

<!-- <app-order-detail [order]="selectedOrder"></app-order-detail> -->

</div>
18 changes: 16 additions & 2 deletions src4/AngularUi/src/app/checkout/checkout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,36 @@ export class CheckoutComponent implements OnInit {
orders: Order[] = [];
items: Item[] = [];
selectedOrder?: Order;
sum: number = 0.0;

ngOnInit(): void {
this.getOrders();
this.getItems();
}

getOrders(): void {
this.orderService.getOrders().subscribe(orders => this.orders = orders);
this.orderService.getOrders().subscribe(orders => {
this.orders = orders;
});
}

getItems(): void {
this.itemService.getItems().subscribe(items => this.items = items);
this.itemService.getItems().subscribe(items => {
this.items = items;
this.sum=items.reduce((sum, current) => sum + current.total, 0);
});
}

onSelect(order: Order): void {
this.selectedOrder = order;
}

donate(): void {
// donate
}

receive(): void {
// receive
}

}

0 comments on commit 3139814

Please sign in to comment.