CartService und Buy-Button auf Detail-Seite hinzugefĆ¼gt
[examples/angular-tutorial] / src / app / product-details / product-details.component.ts
1 import { Component, OnInit } from '@angular/core';
2 import { ActivatedRoute } from '@angular/router';
3 import { products } from '../products';
4 import { CartService } from '../cart.service';
5
6 @Component({
7   selector: 'app-product-details',
8   templateUrl: './product-details.component.html',
9   styleUrls: ['./product-details.component.css']
10 })
11 export class ProductDetailsComponent implements OnInit {
12   product;
13
14   constructor(
15       private route: ActivatedRoute,
16       private cartService: CartService) { }
17
18   ngOnInit() {
19     this.route.paramMap.subscribe(params => {
20       this.product = products[+params.get('productId')];
21     });
22   }
23
24   addToCart(product) {
25     this.cartService.addToCart(product);
26   }
27 }