You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { Router } from '@angular/router';
|
|
import { CartService } from '../../services/cart.service';
|
|
import { Product } from 'src/app/models/product';
|
|
import { Form } from '@angular/forms';
|
|
|
|
|
|
|
|
@Component({
|
|
selector: 'app-cart',
|
|
templateUrl: './cart.component.html',
|
|
styleUrls: ['./cart.component.scss']
|
|
})
|
|
|
|
export class CartComponent implements OnInit {
|
|
|
|
|
|
cartItems: Product[] = []
|
|
totalPrice: number = 0
|
|
|
|
firstname: string = ''
|
|
lastname: string = ''
|
|
email: string = ''
|
|
address: string = ''
|
|
postalcode: string = ''
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private cartService: CartService, private router: Router) { }
|
|
|
|
ngOnInit(): void {
|
|
this.cartItems = this.cartService.getItems()
|
|
this.totalPrice = this.cartService.getTotalPrice()
|
|
console.log(this.cartItems)
|
|
}
|
|
|
|
deleteFromCart(product: Product) {
|
|
this.cartService.removeFromCart(product);
|
|
}
|
|
|
|
onSubmit(): void {
|
|
// Your submit logic here (e.g., making an API call that sends form data)
|
|
this.cartItems = this.cartService.clearCart();
|
|
this.router.navigate(['confirmation']);
|
|
|
|
}
|
|
|
|
|
|
}
|