CartService und Buy-Button auf Detail-Seite hinzugefĆ¼gt
[examples/angular-tutorial] / src / app / cart.service.ts
diff --git a/src/app/cart.service.ts b/src/app/cart.service.ts
new file mode 100644 (file)
index 0000000..aeb5d9e
--- /dev/null
@@ -0,0 +1,24 @@
+import { Injectable } from '@angular/core';
+
+@Injectable({
+  providedIn: 'root'
+})
+export class CartService {
+
+  items= [];
+
+  constructor() { }
+
+  addToCart(product) {
+    this.items.push(product);
+  }
+
+  getItems() {
+    return this.items;
+  }
+
+  clearCart() {
+    this.items = [];
+    return this.items;
+  }
+}