Angular Philosophies

Angular 22 · TypeScript 6.0 · signals · NgRx SignalStore

Years of Angular experience, beside you while you work.

Angular Philosophies is how I write Angular apps, written down: twelve chapters you can read, and the same advice as 132 rules your AI tool follows while it works. For Angular 22.

Install it Watch one review

Changes requested Add orders list page with filters #482 opened by your AI assistant · 1 file changed order-list.component.ts+377 review comments

Hand it to your AI.

Pick your tool. Every line installs the same rules.

The skill and an MCP server in one install. The skill loads when you do Angular work.

/plugin marketplace add tomavic/angular-philosophies
/plugin install angular-philosophies@angular-philosophies

If your project has its own rules, write them above the generated ones. The project wins over the guide.

Or read it yourself.

Twelve chapters, each ending with its rules. Short on time? Start with 03.

09:12Monday morning

You ask your AI tool for a page.

You open Claude Code, Cursor or Copilot and type one line: an orders list with a search box and paging. The kind of page every app has ten of.

You → your AI tool

Add an orders list page with filters.

09:13one minute later

The AI answers in seconds. It compiles, and the list shows up.

You would probably merge it. Most Angular on the internet looks like this, so this is what a model learns to write.

09:14two minutes in

Then I review it. 7 comments.

Each comment quotes a rule from the guide, word for word, and says what goes wrong if you ignore it.

Angular Philosophiesline 4 · 1 of 7

A path that breaks when a folder moves.

Import through path aliases (@shop/..., @/...); never use ../../ across feature or library boundaries.

Three levels of ../ say where the file sits, not what it is. Move the feature and every import like this one breaks.

01 · Architecture

Angular Philosophiesline 16 · 2 of 7

Injection through the constructor.

Inject dependencies with inject() in field initialisers; do not use constructors for injection.

One way to inject, everywhere: components, functions and store features all use inject(), and nothing depends on constructor order.

02 · Components

Angular Philosophiesline 11 · 3 of 7

Undefined until the server answers.

Give every resource a defaultValue and { errorHandling: 'previous value' }; never write ?. or ?? on a resource value in a component.

So the template fills up with ?. and the empty state flashes before the first page arrives.

04 · Data access

Angular Philosophieslines 2, 16, 29, 30 · 4 of 7

The page talks to the server itself.

Make a signalStore the facade, API layer and state layer for its slice; components never inject HttpClient or a data service.

Now the component owns the URL, the params and the error handling, and the next page will copy all three.

03 · The signal store

Angular Philosophieslines 3, 14, 28, 31, 34, 35 · 5 of 7

A subscription kept alive by hand.

Never call .subscribe() in a component; use signals, resources or rxMethod.

Every subscribe is a leak waiting for a missed unsubscribe. This one already has to be closed in two places.

03 · The signal store

Angular Philosophieslines 19, 24, 27 · 6 of 7

A load() that someone has to remember.

Never add a load() method that a component must call after a filter changes; derive reads from state with resources.

Add a status filter tomorrow, forget one call, and the list quietly keeps showing the old result.

03 · The signal store

Angular Philosophieslines 22, 23 · 7 of 7

Search keeps you on page 3.

Reset page to 1 in every filter setter.

Search from page 3 and the server returns page 3 of the results. Usually empty, so the user thinks nothing matched. This one is a real bug.

03 · The signal store

Fixing all seven by hand takes an afternoon.

Or the AI reads the guide before it writes the first line.

09:20eight minutes after the first prompt

Same prompt, this time with the guide.

The component shrinks to what a page is: a store and a template. Everything it did by hand moved into a store that reads from state. From 09:12 to 09:20: eight minutes, and nothing left to fix.

order-list.component.ts
import { Component, OnDestroy, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Subscription } from 'rxjs';
import { Order } from '../../../shared/models/order';
import { Component, inject } from '@angular/core';
import { OrderListStore } from './order-list.store';
import { ORDER_STATUS_OPTIONS } from './order.model';
@Component({
selector: 'app-order-list',
templateUrl: './order-list.component.html',
providers: [OrderListStore],
host: { class: 'block p-4' },
})
export class OrderListComponent implements OnInit, OnDestroy {
export class OrderListComponent {
orders?: Order[];
page = 1;
search = '';
private sub?: Subscription;
constructor(private http: HttpClient) {}
ngOnInit() {
this.load();
}
onSearch(search: string) {
this.search = search;
this.load();
}
load() {
this.sub?.unsubscribe();
this.sub = this.http
.get<Order[]>(`/api/orders?page=${this.page}&q=${this.search}`)
.subscribe(orders => (this.orders = orders));
}
ngOnDestroy() {
this.sub?.unsubscribe();
}
protected readonly store = inject(OrderListStore);
protected readonly statuses = ORDER_STATUS_OPTIONS;
}
  • 14lines in the component, down from 37.
  • Nonesubscribe calls in the component, down from 1.
  • Noneload() calls in the component, down from 3.
  • NoneHttpClient in the component, down from 2.
Open the store it wrote

This is the store the AI writes when it follows the guide. The same code ships with the guide, and it is tested: it compiles under strict TypeScript and its tests pass.

1import { httpResource } from '@angular/common/http';
2import { computed } from '@angular/core';
3import { toObservable, toSignal } from '@angular/core/rxjs-interop';
4import { patchState, signalStore, withComputed, withMethods, withProps, withState } from '@ngrx/signals';
5import { httpMutation, withMutations, withResource } from '@ngrx-toolkit/core';
6import { debounceTime } from 'rxjs';
7import { guardedDevtools } from './guarded-devtools';
8import { Order, OrderStatus, Page } from './order.model';
9
10interface OrderListState {
11 page: number;
12 search: string;
13 status: OrderStatus | null;
14}
15
16const initialState: OrderListState = { page: 1, search: '', status: null };
17const EMPTY_PAGE: Page<Order> = { items: [], total: 0 };
18
19export const OrderListStore = signalStore(
20 guardedDevtools('orderList'),
21 withState(initialState),
22 // A debounced copy of the search box. Derived state stays a signal, never a subscription.
23 withProps(store => ({
24 _debouncedSearch: toSignal(toObservable(store.search).pipe(debounceTime(300)), { initialValue: '' }),
25 })),
26 // Reads are resources derived from state: changing a filter re-derives the request, nobody calls load().
27 withResource(
28 store => ({
29 list: httpResource<Page<Order>>(
30 () => ({
31 url: '/api/orders',
32 params: {
33 page: store.page(),
34 ...(store._debouncedSearch() ? { search: store._debouncedSearch() } : {}),
35 ...(store.status() ? { status: store.status()! } : {}),
36 },
37 }),
38 { defaultValue: EMPTY_PAGE },
39 ),
40 }),
41 { errorHandling: 'previous value' },
42 ),
43 withMutations(store => ({
44 cancel: httpMutation({
45 request: (id: number) => ({ url: `/api/orders/${id}/cancel`, method: 'POST', body: {} }),
46 onSuccess: () => store._listReload(),
47 }),
48 })),
49 withComputed(store => ({
50 pageCount: computed(() => Math.max(1, Math.ceil(store.listValue().total / 20))),
51 })),
52 withMethods(store => ({
53 setSearch(search: string) {
54 patchState(store, { search, page: 1 });
55 },
56 setStatus(status: OrderStatus | null) {
57 patchState(store, { status, page: 1 });
58 },
59 setPage(page: number) {
60 patchState(store, { page });
61 },
62 /** Refetch the same request. A failed reload keeps the last good value; see docs/04-data-access.md. */
63 refresh() {
64 store._listReload();
65 },
66 reset() {
67 patchState(store, initialState);
68 },
69 })),
70);

The advice I would give you while you work, available to your AI tool while it works.