Formular wie in Tutorial ergänzt -- Funzt nicht
[examples/angular-tutorial] / src / app / cart / cart.component.ts
index c9276d4..3d3bb99 100644 (file)
@@ -1,4 +1,6 @@
 import { Component, OnInit } from '@angular/core';
+import { FormBuilder } from '@angular/forms';
+import { CartService } from '../cart.service';
 
 @Component({
   selector: 'app-cart',
@@ -7,9 +9,27 @@ import { Component, OnInit } from '@angular/core';
 })
 export class CartComponent implements OnInit {
 
-  constructor() { }
+  items;
+  checkoutForm;
+
+  constructor(
+      private cartService: CartService,
+      private formBuilder: FormBuilder) {
+    this.checkoutForm = this.formBuilder.group({
+      name: '',
+      address: ''
+    });
+  }
 
   ngOnInit() {
+    this.items = this.cartService.getItems();
   }
 
+  onSubmit(customerData) {
+    // Process checkout data here
+    console.warn('Your order has been submitted', customerData);
+
+    this.items = this.cartService.clearCart();
+    this.checkoutForm.reset();
+  }
 }