Skip to content

Commit

Permalink
Add category selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Popovkov57 committed Sep 27, 2022
1 parent c452c06 commit 42b4cde
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/app/store/store.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
</div>
</div>
<div class="row">
<div class="col-3 bg-info p-2 text-white">
{{categories.length}} Categories
<div class="col-3 p-2">
<div class="d-grid gap-2">
<button class="btn btn-block btn-outline-primary" (click)="changeCategory()">
Home
</button>
<button *ngFor="let category of categories" class="btn btn-outline-primary btn-block" (click)="changeCategory(category)">
{{category}}
</button>
</div>
</div>
<div class="col-9 p-2">
<div *ngFor="let product of products" class="card m-1 p-1 bg-light">
Expand Down
8 changes: 7 additions & 1 deletion src/app/store/store.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ import { ProductRepository } from "../model/product.repository";

export class StoreComponent {

public selectedCategory: string = null;

constructor(private repository: ProductRepository) {}

get products(): Product[] {
return this.repository.getProducts();
return this.repository.getProducts(this.selectedCategory);
}

get categories(): string[] {
return this.repository.getCategories();
}

changeCategory(newCategory?: string) {
this.selectedCategory = newCategory;
}

}

0 comments on commit 42b4cde

Please sign in to comment.