Entities and Custom Features
Manage collections with withEntities.
Entities and Custom Features is a free Angular Academy lesson on CoddyKit. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, and your progress syncs across the web and the CoddyKit app. The Angular Academy course includes 4 lessons in total.
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 existsFeatures 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.
Learn HTML with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 38
- Lessons
- 144
Frequently Asked Questions
Is the “Entities and Custom Features” lesson free?
Yes — any 3 lessons of the Angular Academy learning path, including “Entities and Custom Features”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Angular Academy course includes 4 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.
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
- Creating a SignalStore
- Computed and Methods
- rxMethod for Async Work
- Entities and Custom Features