Filter the shipments list by status

Angular · Angular · advanced · greenfield

Adds client-side status filtering to the shipments list: a signal for the selected status, a computed for the visible rows, and an @empty block for filters that match nothing. The filter recomputes automatically when either the selection or the shipments input changes.

Requirements

Files touched

--- src/app/shipments/shipment-filter.component.ts
+import { Component, computed, input, signal } from '@angular/core';
+
+export interface Shipment {
+  id: string;
+  reference: string;
+  status: 'pending' | 'shipped' | 'delivered';
+}
+
+type StatusFilter = 'all' | Shipment['status'];
+
+@Component({
+  selector: 'app-shipment-filter',
+  standalone: true,
+  template: `
+    <nav class="filters">
+      @for (option of options; track option) {
+        <button
+          type="button"
+          [class.active]="status() === option"
+          [attr.aria-pressed]="status() === option"
+          (click)="status.set(option)"
+        >
+          {{ option }}
+        </button>
+      }
+    </nav>
+    <ul class="shipments">
+      @for (shipment of visible(); track shipment.id) {
+        <li>{{ shipment.reference }} — {{ shipment.status }}</li>

Review this PR

Angular practice