Shipping-Component mit Data-Fetch über HTTP
[examples/angular-tutorial] / src / app / cart.service.ts
1 import { Injectable } from '@angular/core';
2 import { HttpClient } from '@angular/common/http';
3
4 @Injectable({
5   providedIn: 'root'
6 })
7 export class CartService {
8
9   items= [];
10
11   constructor(private http: HttpClient) { }
12
13   addToCart(product) {
14     this.items.push(product);
15   }
16
17   getItems() {
18     return this.items;
19   }
20
21   clearCart() {
22     this.items = [];
23     return this.items;
24   }
25   
26   getShippingPrices() {
27     return this.http.get('/assets/shipping.json');
28   }
29 }