export const increment = createAction('[Counter] Increment');
export const counterReducer = createReducer(
0,
on(increment, (state) => state + 1)
);
Topics
42
Accessibility (a11y) in Angular
Angular Animations
Angular CDK (Component Dev Kit)
Angular CLI & Project Structure
Angular DevTools & Debugging
Angular Elements (Web Components)
Angular Material & UI Component Libraries
Angular Material Theming
Angular Schematics & Custom Builders
Angular Security (XSS, Sanitization & CSP)
Angular Signals
Angular Style Guide & Best Practices
Build, Environments & Deployment
Change Detection
Components & Templates
Content Projection (ng-content)
Data Binding
Dependency Injection Providers & Injection Tokens
Directives
End to End Testing with Cypress & Playwright
Forms
HTTP Client & Interceptors
Internationalization (i18n) in Angular
Lifecycle Hooks
Micro Frontends with Angular
New Control Flow Syntax (@if, @for & @switch)
NgModules & Modular Architecture
NgRx State Management
Performance & Lazy Loading
Pipes (Built-in & Custom)
Progressive Web Apps (PWA) with Angular
Router Guards & Resolvers
Routing
RxJS & Observables
Server-Side Rendering with Angular Universal
Services & Dependency Injection
Standalone Components
State Management
Template Reference Variables & ViewChild
Testing with Jasmine & Karma
TypeScript with Angular
Zoneless Change Detection & Zone.js
NgRx State Management
5 questions found
NgRx is a state management library for Angular, inspired by Redux, that keeps all of an app's shared state in one single central store. The only way to change that state is by dispatching a plain object called an action to a function called a reducer, making it very clear and predictable how and why state changes across a large app.
Real-world example
A large e commerce app uses NgRx to manage its shopping cart, user session, and notification data all in one predictable, central place, making it easier for a large team to understand exactly how and where state changes happen.
State Management;Angular Signals
How do you select a specific piece of state from the NgRx store and use it in a component?
IntermediateYou use a selector function, created with createSelector, to describe exactly which piece of state you want, then inject the Store service and call its select method with that selector, receiving an observable that automatically emits whenever that specific piece of state changes.
export const selectCartItems = createSelector(
(state: AppState) => state.cart,
(cart) => cart.items
);
constructor(private store: Store<AppState>) {}
cartItems$ = this.store.select(selectCartItems);
Real-world example
A shopping cart badge component displays the current number of items by selecting just that specific piece of state from the store, automatically updating whenever an item is added or removed anywhere else in the app.
RxJS & Observables;Components & Templates
How do NgRx Effects let you handle asynchronous operations, like an API call, in response to a dispatched action?
AdvancedAn Effect listens for a specific action, performs an asynchronous operation like an HTTP request, and then dispatches a new action once that operation completes, keeping asynchronous side effects cleanly separated from the pure, synchronous reducer functions that update the actual state.
loadUsers$ = createEffect(() =>
this.actions$.pipe(
ofType(loadUsers),
mergeMap(() => this.userService.getUsers().pipe(
map((users) => loadUsersSuccess({ users })),
catchError((error) => of(loadUsersFailure({ error })))
))
)
);
Real-world example
A user management page dispatches a loadUsers action, triggering an Effect that fetches the actual data from the server and dispatches a success action with the results, keeping the reducer itself completely free of any asynchronous logic.
HTTP Client & Interceptors;RxJS & Observables
What is the NgRx Entity library, and how does it simplify managing collections of data, like a list of users?
IntermediateNgRx Entity provides a standard, normalized way to store collections of similar items, keyed by their unique id, along with prebuilt functions for common operations like adding, updating, and removing entries, saving you from writing repetitive boilerplate code for managing lists of data in your reducers.
export interface UserState extends EntityState<User> {}
export const adapter = createEntityAdapter<User>();
export const initialState = adapter.getInitialState();
export const reducer = createReducer(
initialState,
on(addUser, (state, { user }) => adapter.addOne(user, state))
);
Real-world example
A user management feature manages its list of users using NgRx Entity, gaining reliable, well tested add, update, and remove operations without needing to hand write that repetitive array manipulation logic themselves.
State Management;Design Patterns in Angular
How do you decide between using NgRx, signals, or a simple service for managing state in an Angular app?
BeginnerFor small to medium apps, a simple service combined with signals is often perfectly sufficient and much easier to learn. NgRx becomes valuable for very large apps with complex, frequently changing shared state across many features, or when a large team needs the strict predictability and tooling, like time travel debugging, that NgRx provides.
// Simple approach, sufficient for many apps
@Injectable({ providedIn: 'root' })
export class CartService {
items = signal<Item[]>([]);
}
// NgRx, better suited for large, complex shared state across many features
this.store.dispatch(addItem({ item }));
Real-world example
A small internal tool sticks with a simple signal based service for managing its state, while a large enterprise application with dozens of interacting features adopts NgRx for its stricter, more predictable structure.
State Management;Angular Signals