Formular wie in Tutorial ergänzt -- Funzt nicht
[examples/angular-tutorial] / src / app / cart / cart.component.ts
1 import { Component, OnInit } from '@angular/core';
2 import { FormBuilder } from '@angular/forms';
3 import { CartService } from '../cart.service';
4
5 @Component({
6   selector: 'app-cart',
7   templateUrl: './cart.component.html',
8   styleUrls: ['./cart.component.css']
9 })
10 export class CartComponent implements OnInit {
11
12   items;
13   checkoutForm;
14
15   constructor(
16       private cartService: CartService,
17       private formBuilder: FormBuilder) {
18     this.checkoutForm = this.formBuilder.group({
19       name: '',
20       address: ''
21     });
22   }
23
24   ngOnInit() {
25     this.items = this.cartService.getItems();
26   }
27
28   onSubmit(customerData) {
29     // Process checkout data here
30     console.warn('Your order has been submitted', customerData);
31
32     this.items = this.cartService.clearCart();
33     this.checkoutForm.reset();
34   }
35 }