0Pricing
Angular Academy · Lesson

Entities and Custom Features

Manage collections with withEntities.

Entities and Custom Features is a free Angular Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Managing Collections

Lists of records (todos, users, products) are so common that NgRx provides withEntities to manage them with normalized state and ready-made updater functions.

withEntities

withEntities stores items keyed by id in an entityMap plus an ordered ids array, and exposes an entities computed signal of the list.

import { withEntities } from '@ngrx/signals/entities';

export const TodoStore = signalStore(
  withEntities<Todo>()
);
// store.entities() -> Todo[]

Entity Updaters

Use updater helpers with patchState: setAllEntities, addEntity, updateEntity, removeEntity. They keep the map and id order consistent.

import { addEntity, removeEntity, updateEntity } from '@ngrx/signals/entities';

patchState(store, addEntity({ id: '1', title: 'A', done: false }));
patchState(store, updateEntity({ id: '1', changes: { done: true } }));
patchState(store, removeEntity('1'));

Loading A Collection

Replace the whole collection after a fetch with setAllEntities, which normalizes the array into the map and ids.

import { setAllEntities } from '@ngrx/signals/entities';

load: rxMethod<void>(pipe(
  switchMap(() => api.getTodos()),
  tap(todos => patchState(store, setAllEntities(todos)))
))

Custom idKey

If your entity's identifier is not id, pass a selector. The store then keys the map by that field.

withEntities<User>(); // expects user.id
// custom key:
patchState(store, addEntity(user, { selectId: (u: User) => u.uuid }));

Deriving From Entities

Combine withEntities with withComputed to build filtered or counted read models on top of the collection.

withComputed(({ entities }) => ({
  remaining: computed(() => entities().filter(t => !t.done).length)
}))

What Is A Custom Feature

A custom feature is a reusable bundle of state, computed, and methods you can drop into many stores. Create one with signalStoreFeature.

import { signalStoreFeature, withState } from '@ngrx/signals';

export function withLoading() {
  return signalStoreFeature(
    withState({ loading: false })
  );
}

Reusing A Feature

Add your custom feature to any store just like a built-in one. This is how you share cross-cutting concerns like loading flags or pagination.

export const TodoStore = signalStore(
  withLoading(),
  withEntities<Todo>()
);
// store.loading() now exists

Features With Methods

A custom feature can include withMethods to expose reusable behavior, such as setLoading helpers.

export function withLoading() {
  return signalStoreFeature(
    withState({ loading: false }),
    withMethods((store) => ({
      setLoading(loading: boolean) { patchState(store, { loading }); }
    }))
  );
}

Composability

Because features are just functions returning feature descriptors, you can stack many: withLoading(), withEntities(), plus app-specific state, all merged into one strongly typed store.

Generic Features

Make features generic to work across entity types. Type parameters flow through so consumers keep full type safety.

export function withSelected<T>() {
  return signalStoreFeature(
    withState({ selected: null as T | null })
  );
}

Quick Check

Check your entities and features knowledge.

Recap

You managed collections with withEntities (normalized map, updater helpers, derived read models) and built reusable, generic signalStoreFeature bundles to share state, computed, and methods across stores.

Frequently asked questions

Is the “Entities and Custom Features” lesson free?

Yes — the full text of “Entities and Custom Features” is free to read here on the web, and the Angular Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Angular Academy course, upgrade to CoddyKit PRO.

What will I learn in “Entities and Custom Features”?

Manage collections with withEntities. You practise Angular Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Angular Academy?

No prior experience is required. Angular Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Entities and Custom Features” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Angular Academy lesson?

Yes. Every Angular Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Creating a SignalStore
  2. Computed and Methods
  3. rxMethod for Async Work
  4. Entities and Custom Features
← Back to Angular Academy