Skip to content

Commit

Permalink
Add detail and checkout component and routing
Browse files Browse the repository at this point in the history
  • Loading branch information
Popovkov57 committed Sep 28, 2022
1 parent 60459a6 commit 4ff93ac
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Component } from '@angular/core';

@Component({
selector: 'app',
template: "<store></store>"
template: "<router-outlet></router-outlet>"
})
export class AppComponent {}
15 changes: 11 additions & 4 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { StoreModule } from './store/store.module';

import { AppComponent } from './app.component';
import { StoreComponent } from './store/store.component';
import { CheckoutComponent } from './store/checkout.component';
import { CartDetailComponent } from './store/cartDetail.component';
import { RouterModule } from '@angular/router';

@NgModule({
imports: [BrowserModule, StoreModule,
RouterModule.forRoot([
{ path: "store", component: StoreComponent },
{ path: "cart", component: CartDetailComponent },
{ path: "checkout", component: CheckoutComponent },
{ path: "**", redirectTo: "/store" }
])],
declarations: [
AppComponent
],
imports: [
BrowserModule, StoreModule
],
providers: [],
bootstrap: [AppComponent]
})
Expand Down
7 changes: 7 additions & 0 deletions src/app/store/cartDetail.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Component } from "@angular/core";

@Component({
template:`<div><h3 class="bg-info p-1 text-white">Cart Detail Component</h3></div>`
})

export class CartDetailComponent {}
2 changes: 1 addition & 1 deletion src/app/store/cartSummary.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(empty)
</span>
</small>
<button class="btn btn-sm bg-dark text-white" [disabled]="cart.itemCount == 0">
<button class="btn btn-sm bg-dark text-white" [disabled]="cart.itemCount == 0" routerLink="/cart">
<i class="fa fa-shopping-cart"></i>
</button>
</div>
7 changes: 7 additions & 0 deletions src/app/store/checkout.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Component } from "@angular/core";

@Component({
template:`<div><h3 class="bg-info p-1 text-white">Checkout Component</h3></div>`
})

export class CheckoutComponent {}
4 changes: 3 additions & 1 deletion src/app/store/store.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component } from "@angular/core";
import { Product } from "../model/product.model";
import { ProductRepository } from "../model/product.repository";
import { Cart } from "../model/cart.model";
import { Router } from "@angular/router";

@Component({
selector: "store",
Expand All @@ -14,7 +15,7 @@ export class StoreComponent {
public productsPerPage = 4;
public selectedPage = 1;

constructor(private repository: ProductRepository, private cart: Cart) {}
constructor(private repository: ProductRepository, private cart: Cart, private router: Router) {}

get products(): Product[] {
let pageIndex = (this.selectedPage - 1) * this.productsPerPage;
Expand Down Expand Up @@ -44,6 +45,7 @@ export class StoreComponent {

addProductToCart(product: Product) {
this.cart.addLine(product, 1);
this.router.navigateByUrl("/cart");
}

}
9 changes: 6 additions & 3 deletions src/app/store/store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { FormsModule } from "@angular/forms";
import { ModelModule } from "../model/model.module";
import { StoreComponent } from "./store.component";
import { CartSummaryComponent } from "./cartSummary.component";
import { CartDetailComponent } from "./cartDetail.component";
import { CheckoutComponent } from "./checkout.component";
import { RouterModule } from "@angular/router";

@NgModule({
imports: [ModelModule, BrowserModule, FormsModule],
declarations: [StoreComponent, CartSummaryComponent],
exports: [StoreComponent, CartSummaryComponent]
imports: [ModelModule, BrowserModule, FormsModule, RouterModule],
declarations: [StoreComponent, CartSummaryComponent, CartDetailComponent, CheckoutComponent],
exports: [StoreComponent, CartSummaryComponent, CartDetailComponent, CheckoutComponent]
})

export class StoreModule {}

0 comments on commit 4ff93ac

Please sign in to comment.