Created
September 22, 2019 21:18
-
-
Save LayZeeDK/c15df413c801dde258d6187cbbe9f32b to your computer and use it in GitHub Desktop.
Cart: Initial mixed component.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h3>Cart</h3> | |
<p> | |
<a routerLink="/shipping">Shipping Prices</a> | |
</p> | |
<div class="cart-item" *ngFor="let item of items"> | |
<span>{{ item.name }} </span> | |
<span>{{ item.price | currency }}</span> | |
</div> | |
<form [formGroup]="checkoutForm" (ngSubmit)="onSubmit(checkoutForm.value)"> | |
<div> | |
<label for="name"> | |
Name | |
</label> | |
<input id="name" type="text" formControlName="name"> | |
</div> | |
<div> | |
<label for="address"> | |
Address | |
</label> | |
<input id="address" type="text" formControlName="address"> | |
</div> | |
<button class="button" type="submit">Purchase</button> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { FormBuilder } from '@angular/forms'; | |
import { CartService } from '../cart.service'; | |
@Component({ | |
selector: 'app-cart', | |
styleUrls: ['./cart.component.css'], | |
templateUrl: './cart.component.html', | |
}) | |
export class CartComponent { | |
items; | |
checkoutForm; | |
constructor( | |
private cartService: CartService, | |
private formBuilder: FormBuilder, | |
) { | |
this.items = this.cartService.getItems(); | |
this.checkoutForm = this.formBuilder.group({ | |
name: '', | |
address: '', | |
}); | |
} | |
onSubmit(customerData) { | |
// Process checkout data here | |
console.warn('Your order has been submitted', customerData); | |
this.items = this.cartService.clearCart(); | |
this.checkoutForm.reset(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment