Project 2: Product Catalog with API, Routing and Search

Angular 20 min min read Updated: Nov 16, 2026 Intermediate
Project 2: Product Catalog with API, Routing and Search
Intermediate Topic 2 of 4

What We Build

  • /products list with search, category filter and pagination
  • /products/:id detail page
  • Loading and error states
  • Lazy-loaded routes
API: We use the free https://dummyjson.com/products API. If the site is unavailable, run a local json-server with similar data.
bash g new catalog --style=css cd catalog ng generate service products/product-api ng generate component products/product-list ng generate component products/product-detail

Step 1: Models and API Service

typescript // products/product.model.ts export interface Product { id: number; title: string; description: string; price: number; rating: number; category: string; thumbnail: string; } export interface ProductPage { products: Product[]; total: number; skip: number; limit: number; }
typescript // products/product-api.ts @Injectable({ providedIn: 'root' }) export class ProductApi { private http = inject(HttpClient); private base = 'https://dummyjson.com/products'; list(opts: { q: string; category: string; page: number; size: number }) { const skip = (opts.page - 1) * opts.size; let url = this.base; let params = new HttpParams().set('limit', opts.size).set('skip', skip); if (opts.q) { url = `${this.base}/search`; params = params.set('q', opts.q); } else if (opts.category) { url = `${this.base}/category/${opts.category}`; } return this.http.get<ProductPage>(url, { params }); } get(id: number) { return this.http.get<Product>(`${this.base}/${id}`); } categories() { return this.http.get<{ slug: string; name: string }[]>(`${this.base}/categories`); } }

Step 2: Routes (Lazy)

typescript // app.routes.ts export const routes: Routes = [ { path: '', pathMatch: 'full', redirectTo: 'products' }, { path: 'products', children: [ { path: '', loadComponent: () => import('./products/product-list/product-list').then(m => m.ProductList), title: 'Products' }, { path: ':id', loadComponent: () => import('./products/product-detail/product-detail').then(m => m.ProductDetail), title: 'Product details' }, ], }, { path: '**', redirectTo: 'products' }, ]; // app.config.ts provideRouter(routes, withComponentInputBinding()), provideHttpClient(withFetch()),

Step 3: List Page

typescript export class ProductList { private api = inject(ProductApi); q = signal(''); category = signal(''); page = signal(1); size = 12; categories = toSignal(this.api.categories(), { initialValue: [] }); data = rxResource({ params: () => ({ q: this.q(), category: this.category(), page: this.page(), size: this.size }), stream: ({ params }) => this.api.list(params), }); products = computed(() => this.data.value()?.products ?? []); pages = computed(() => Math.ceil((this.data.value()?.total ?? 0) / this.size)); search(value: string) { this.q.set(value); this.page.set(1); } pickCategory(slug: string) { this.category.set(slug); this.q.set(''); this.page.set(1); } }
Resource option names: rxResource used request in older previews and params in newer versions. If your editor shows an error, use the name from your Angular version's docs.
html <h1>Products</h1> <div class="filters"> <input #box placeholder="Search products" (keydown.enter)="search(box.value)"> <button (click)="search(box.value)">Search</button> <select #cat (change)="pickCategory(cat.value)"> <option value="">All categories</option> @for (c of categories(); track c.slug) { <option [value]="c.slug">{{ c.name }}</option> } </select> </div> @if (data.isLoading()) { <p>Loading products...</p> } @else if (data.error()) { <p class="error">Could not load products. <button (click)="data.reload()">Retry</button></p> } @else { <div class="grid"> @for (p of products(); track p.id) { <a class="card" [routerLink]="['/products', p.id]"> <img [src]="p.thumbnail" [alt]="p.title" width="200" height="200" loading="lazy"> <h3>{{ p.title }}</h3> <p>{{ p.price | currency }} &middot; {{ p.rating }} stars</p> </a> } @empty { <p>No products found.</p> } </div> <div class="pager"> <button (click)="page.update(p => p - 1)" [disabled]="page() === 1">Previous</button> <span>Page {{ page() }} of {{ pages() }}</span> <button (click)="page.update(p => p + 1)" [disabled]="page() >= pages()">Next</button> </div> }

Step 4: Detail Page with Input Binding

typescript export class ProductDetail { id = input.required<string>(); // route param, thanks to withComponentInputBinding() private api = inject(ProductApi); product = rxResource({ params: () => Number(this.id()), stream: ({ params }) => this.api.get(params), }); }
html <a routerLink="/products">&larr; Back to products</a> @if (product.isLoading()) { <p>Loading...</p> } @else if (product.error()) { <p class="error">Product not found.</p> } @else if (product.value(); as p) { <article> <img [src]="p.thumbnail" [alt]="p.title" width="300" height="300"> <h1>{{ p.title }}</h1> <p class="price">{{ p.price | currency }}</p> <p>{{ p.description }}</p> <p>Category: {{ p.category }} | Rating: {{ p.rating }}</p> </article> }

Practice Ideas

  • Sort by price or rating
  • Remember filters in the URL with query params
  • Add a favorites list saved in localStorage
  • Add a skeleton loader with @defer
  • Write tests for ProductApi using HttpTestingController

Conclusion

The catalog joins an API service, lazy routes with input binding, reactive resources for search and paging, and loading and error states. This is the shape of most real apps.

Quick Summary: ProductApi + lazy routes + rxResource(params) + detail via input binding.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators