checkout.component.ts 639 B

12345678910111213141516171819202122232425
  1. import { Component } from "@angular/core";
  2. import { Router } from "@angular/router";
  3. import { Store } from "../services/store.service";
  4. @Component({
  5. selector: "checkout",
  6. templateUrl: "checkout.component.html",
  7. styleUrls: ['checkout.component.css']
  8. })
  9. export class Checkout {
  10. public errorMessage = "";
  11. constructor(public store: Store, private router: Router) {}
  12. onCheckout() {
  13. this.errorMessage = "";
  14. this.store.checkout()
  15. .subscribe(() => {
  16. this.router.navigate(["/"]);
  17. }, err => {
  18. this.errorMessage = `Failed to checkout: ${err}`;
  19. });
  20. }
  21. }